Back to Prompt Library

Code Generation

A code generation prompt for creating implementation-ready code with constraints, interfaces, acceptance criteria, and tests.

Reviewed: 2026-03-18

Use this when you need the model to generate new code from a specification and you want fewer vague or toy outputs.

Prompt Template

You are building production-ready {language} code.

Build:
{feature_request}

Project context:
- Runtime/framework: {runtime}
- Existing interfaces or contracts: {interfaces}
- Constraints: {constraints}
- Input/output expectations: {io_requirements}
- Acceptance criteria: {acceptance_criteria}

Return exactly:
1. A short implementation plan.
2. The final code in fenced blocks.
3. Minimal usage example.
4. Tests or validation cases.

Customize the variables before using the template in production workflows.

Best for

  • Generating a reusable utility or API route
  • Scaffolding a feature with strict constraints
  • Building a UI component from explicit requirements

Expected output

  • Implementation plan
  • Production-focused code
  • Usage example
  • Validation or tests

Variables to customize

language

Primary language

Example: TypeScript

feature_request

What should be built

Example: A paginated search helper for server-side routes

runtime

Framework and runtime

Example: Next.js route handler on Node

interfaces

Existing contracts or shapes

Example: SearchParams, SearchResponse

constraints

Hard implementation limits

Example: No external packages; must support abort signals

io_requirements

Input and output behavior

Example: Return stable JSON with pageInfo and items

acceptance_criteria

Definition of done

Example: Handles empty queries, bad pages, and server errors cleanly

Optimization tips

  • Give the model your existing types and interfaces instead of describing them loosely.
  • State non-goals to prevent unnecessary abstractions.
  • Ask for the smallest version that still meets your acceptance criteria.

Example use case

Generate a server-safe Open Graph metadata helper for a multilingual Next.js site.

Expected result

The model returns a focused implementation, a usage snippet, and the scenarios you should verify.

References