Chapter 05
5 / 38

High-Quality Prompt Templates

⏱️ 12 min

In day-to-day development, fixed templates let you consistently reproduce good results. Here are 3 patterns you can use right away.

Task + Context + Constraints + Output + Acceptance

[Task] Implement frontend validation logic for a login form
[Context] Using React + TypeScript, existing components Form and Input, can reuse hooks/useToast
[Constraints] Don't add new dependencies; return specific field-level error messages on failure
[Output] Complete code block with type definitions; include 2 input/output examples
[Acceptance] Code must pass ESLint; explain which edge cases are covered

This works for the vast majority of feature work. The key is spelling out "where the project stands now" and "what counts as done."

Role + Steps + Checklist

You're a code review assistant. Follow these steps:
1) Read @pages/login.tsx and @components/Form.tsx
2) Find accessibility issues that can be improved
3) Output a fix as a patch (in a Markdown code block), then list a checklist
Checklist: keyboard navigable, fields have labels, error messages are screen-reader accessible

Good for refactoring, reviews, and accessibility audits — anything that benefits from a structured checklist.

Diff/Patch Instructions

Generate a patch for @components/Button.tsx:
- Change the primary button background to #0f172a, add shadow on hover
- Keep props unchanged, don't break existing usage
- Output a unified diff, don't include unrelated files

When you're making small changes to existing code, asking for a patch minimizes collateral damage and unrelated modifications.

Practice

  • Pick one of the patterns above and run it in Cursor against your current project. See if AI follows the format.
  • Tweak the "constraints" and "acceptance" fields, observe how the output changes, and start building your own template library.

📚 Related resources

Common questions

Open a question to review the practical answer.

When should I reach for the Task + Context + Constraints + Output + Acceptance template?

Use it for almost any feature work — new components, form validation, utilities, API wiring. The key is spelling out the existing landscape (current Form / Input / hooks you can reuse) and the acceptance bar (passes ESLint, covers empty-input edge case). Skip those two and AI ships generic code. The template looks verbose but saves 3 rounds of rework versus "write me a login validator."

What kind of work is the Role + Steps + Checklist pattern best for?

It fits review, refactor, and a11y audits — anywhere checklist-style verification matters. Example: make AI the code reviewer — read @pages/login.tsx and @components/Form.tsx, surface a11y issues, then return a patch plus a checklist (keyboard navigable / labels present / errors readable by screen readers). The checklist is the magic — front-loaded acceptance auto-aligns the output.

When should I ask AI for a unified diff instead of full code?

Whenever you're tweaking existing code. Example: change @components/Button.tsx primary color to #0f172a and add hover shadow, keep props unchanged. Asking for a unified diff instead of the full file stops AI from also "helpfully" reformatting unrelated imports, styles, or comments — those full-file rewrites routinely produce 30+ lines of noise diff that reviewers hate.

How do I turn working prompts into a reusable template library?

Three steps: (1) save every prompt that worked into a local file (prompts/ folder or Notion) the moment it does — don't rely on memory; (2) tag the use case — "React component" vs "PR review"; (3) use placeholders like [filename], [stack], [acceptance] so reuse is copy-paste. After 3 months that library is the actual delta between you and a colleague who keeps re-typing prompts.

What if AI ignores the format I asked for (unified diff / table / checklist)?

Reply directly: "Re-output as unified diff format, no unrelated files" — don't re-explain the whole task. AI sometimes drops format constraints, especially in long contexts. Repeating the format requirement once almost always lands. If 2 retries still fail, move the format constraint to the very end of the prompt (last instruction wins) and it usually clicks immediately.