Writing Great Prompts
The five ingredients of a prompt that gets good code.
A good coding prompt gives the model everything it needs to make good decisions. Use this structure:
The five ingredients
- Role β who the model should act as.
- Context β the files, stack, and constraints.
- Task β one clear, specific goal.
- Constraints β what NOT to do.
- Definition of done β how we'll know it's correct.
Example: weak vs strong
Weak:
"fix the login bug"
Strong:
You are a senior TypeScript engineer. Insrc/auth/login.ts, the login function fails when the email contains uppercase letters because the lookup is case-sensitive. Task: normalize the email to lowercase before the lookup. Constraints: do not change the password hashing, do not touch the UI. Done when:npm testpasses and a new test covers"User@Example.com".
The strong prompt names the file, the cause, the fix, the constraints, and the test.
Rules of thumb
- Be specific about the "where". "Fix the bug in X" beats "fix the bug".
- Give the acceptance criteria. "Done when tests pass" is a real requirement.
- Show, don't describe. Paste a failing test or error message.
- One task per prompt. Two tasks = two chances to drift.
- State constraints. What must stay untouched is as important as what must change.
When to be less specific
If you're exploring ("how could I structure this?"), loosen the constraints and ask for options:
"Suggest three ways to structure the caching layer, with trade-offs. Don't write code yet."
The prompt is a spec. Vague specs produce vague code β precise specs produce code you can actually merge.