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.

AI Prompts·25 commands·Last updated 2026-08-23

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 needed
Scope the edit
Do not refactor unrelated code; minimal diff
Limit scope
Explain the approach before code
See 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 throws
Signature contract
No new deps; reuse existing utils
Dependency constraint
Naming per {project convention}; no emoji/abbrev
Style 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 crash
Error-handling contract
Mind {perf/memory} limits; state complexity
Perf awareness
Flag likely failure points and fallbacks
Robustness hint

Acceptance & Delivery 5

Acceptance: {passes X test / output matches Y}
Checkable acceptance
Give a usage example with expected output
Example is docs
Note integration points with existing code
Integration hint
List uncovered risks or assumptions
Transparent assumptions
If cannot fully satisfy, state the trade-off first
Honest degradation

Pitfalls 5

Full context beats long prose
Paste code over adjectives
Pin signature/contract to stay on track
Clear boundaries
Ask for tests, esp. exception paths
Exceptions get missed
Minimal-diff principle
Don't refactor along the way
Make acceptance checkable
Vague 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 Us

Edit this page on GitHub

Edit the source file directly and open a PR to improve this cheatsheet.