Code-generation Prompt Cheatsheet - Requirement/Context/Constraints/Acceptance
Code-generation prompt templates organized by module — requirement/context, constraints, I/O contract, edge/tests, acceptance. Copy a template, fill the variables, and ship.
Requirement & Context 5
Task: {do X}. Context: {existing structure/deps}.Task + context in one shot
Relevant code:
```{lang}
{code}
```Paste snippets to cut ambiguity
Target file/func: {path#func}; change only what is neededScope the edit
Do not refactor unrelated code; minimal diffLimit scope
Explain the approach before codeSee the plan first
Constraints & Contract 5
Lang/framework/version: {TS 5 + Nuxt 4}; follow {style guide}Explicit tech constraints
Signature must be: {in type} → {out type}; no undeclared throwsSignature contract
No new deps; reuse existing utilsDependency constraint
Naming per {project convention}; no emoji/abbrevStyle consistency
Support {Node 20+ / latest 2 browser versions}Runtime constraint
Edge & Tests 5
Handle edges: {empty/overlong/invalid type/concurrency}Edge checklist
Give 3 unit tests (incl. one exception path)Normal + exception coverage
On invalid input, return {clear error}, not a crashError-handling contract
Mind {perf/memory} limits; state complexityPerf awareness
Flag likely failure points and fallbacksRobustness hint
Acceptance & Delivery 5
Acceptance: {passes X test / output matches Y}Checkable acceptance
Give a usage example with expected outputExample is docs
Note integration points with existing codeIntegration hint
List uncovered risks or assumptionsTransparent assumptions
If cannot fully satisfy, state the trade-off firstHonest degradation
Pitfalls 5
Full context beats long prosePaste code over adjectives
Pin signature/contract to stay on trackClear boundaries
Ask for tests, esp. exception pathsExceptions get missed
Minimal-diff principleDon't refactor along the way
Make acceptance checkableVague fails acceptance
Tips
- The core of code-gen prompts is handing over task, context, constraints, and acceptance in one shot — pasting relevant code cuts ambiguity better than adjectives.
- Explicit language/framework/version constraints + a function-signature contract pull the model from "free improvisation" back to "implement to spec".
- Edges and tests (especially exception paths) get missed most — list an edge checklist and demand unit tests to raise usability sharply.
- Minimal-diff principle + checkable acceptance make generated code easy to review and merge.
Official References
Commands are compiled from the official docs below. Click to verify the latest usage.
Maintained by LaoHand
Publicly updated on Aug 23, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact UsEdit this page on GitHub
Edit the source file directly and open a PR to improve this cheatsheet.