Anatomy of a good prompt
The six parts of a prompt that gets production-sane code on the first try.
10 min read · Last reviewed November 20, 2026
Anatomy of a good prompt
A good prompt is a small spec: it says what to build, inside which constraints, and how to know it's done.
You'll be able to#
- Turn a vague idea into a spec an can execute
- Know which details matter and which to leave to the agent
The mental model#
Imagine handing the task to a capable contractor who has never seen your project and can't read your mind. Whatever you don't specify, they'll fill in with the most common choice in their training data, which may not be what you want.
The six parts#
| Part | Question it answers | Example |
|---|---|---|
| Goal | What and why? | "Users can reset their password by email." |
| Context | Where does this live? | "Next.js 15 App Router, Drizzle + Postgres, auth via Better Auth." |
| Interfaces | What are the inputs, outputs and contracts? | "POST /api/reset with { email } → always 200." |
| Constraints | What rules must it follow? | "Tokens expire in 30 min, single-use, hashed at rest." |
| Non-goals | What should it not touch? | "Don't change the login page or add new deps." |
| Verification | How do we know it works? | "Add tests for expired, reused, and valid tokens; run them." |
Try it: build a prompt#
Fill in the parts below, or load an example, and copy the result. Parts you leave empty are left out.
Build a strong prompt
Fill in the fields above, or pick an example, and your prompt appears here.
Key concepts#
- Specificity where it matters: Pin down things that are expensive to change later (data models, contracts, security rules). Leave cosmetic details loose.
- Examples beat adjectives: "Like Stripe's dashboard tables" says more than "clean and modern."
- Iterate small: Three focused prompts beat one giant one.
Decisions you make (not the agent)#
Your call, not the agent's
| Decision | Sensible default | Choose otherwise when… |
|---|---|---|
| How much detail | Pin down what is expensive to change (data models, API contracts, security rules); leave cosmetic details loose | A throwaway prototype: a sentence or two is enough |
| One prompt or several | Several small prompts, each ending with a check | A tiny, well-understood change |
| Plan first | Yes, for anything touching more than a file or two | A one-line fix |
| Examples or adjectives | Show an example or point to a reference ("match lib/bookings.ts") | The style is already obvious from nearby code |
| Who settles ambiguous choices | You do, in the prompt | You're exploring: ask the agent to list its assumptions first |
| Verification | Name the command or test that proves it works | An exploratory spike you will throw away |
What good output looks like#
- The agent restates the task and the boundaries you set, or asks about a real gap, before it builds
- The plan matches your constraints and names the files it will touch
- The diff stays inside the non-goals you listed
- Tests and checks you asked for exist, and the agent shows their output
- Anything it assumed is stated, not buried
Red flags in your own prompts#
- Adjectives without criteria ("make it secure," "make it fast")
- No stack mentioned, so the agent picks one for you
- No , so "done" means "it compiled, maybe"
- Common agent mistakes when the prompt is thin: it picks a stack you didn't want, adds a dependency you didn't ask for, changes unrelated files, or reports "done" without running anything. Each one maps to a missing part: context, constraints, non-goals, verification.
Worked example#
Task: "Make the bookings page faster."
You send exactly that sentence. The agent adds caching to the data layer, memoizes several components and reports that the page is now optimized.
What a good result contains: a measurement of the page before the change, the one or two changes that account for most of the cost, and a measurement after with the same method, plus a check that behavior did not change.
The wrong turn: nothing was measured, so the agent optimized what looked slow. The new cache serves out-of-date bookings for a minute after someone cancels, which is a behavior change nobody asked for, and the page was slow because of one query, which was never touched.
How review catches it: ask what was measured before and after. There is no number, so the claim is unproven. Then rewrite the prompt using the six parts: a Goal with a measurable target, the Context (stack and the slow page), a Constraint that behavior must not change, a against adding caching layers, and Verification that runs the same measurement before and after and reruns the booking tests. The second attempt starts by measuring.
Sample prompts#
Weak vs strong#
Add password reset.
Why it fails: The agent has to guess the flow, token storage, expiry, email provider and UI. Some of those guesses will be wrong, and some will be insecure.
Goal: Add a password reset flow. Context: Next.js 15 (App Router), TypeScript, Drizzle ORM + Postgres, Resend for email. Interfaces: - /forgot-password page: email field → POST /api/auth/forgot - /reset-password?token=… page: new password + confirm → POST /api/auth/reset Constraints: - Forgot endpoint always returns 200 (don't reveal whether an email exists) - Token: 32+ random bytes, store only a SHA-256 hash, expires in 30 min, single use - Rate limit forgot endpoint to 5 requests/hour per IP and per email - Hash passwords with the existing helper in lib/auth/password.ts Non-goals: Don't modify login/signup. No new dependencies. Verification: Add a migration for the tokens table. Write tests for valid, expired, reused, and unknown-email cases. Run tests and type-check and show me the output.
Why it works: Every expensive decision is made up front, the security properties are spelled out, and the agent knows how to prove it's finished.
What changed
- Context names the stack and the email provider, so the agent doesn't pick for you
- Interfaces define the pages and endpoints
- Constraints spell out the security rules (token size, hashing, expiry, single use, rate limits)
- Non-goals keep it away from login and signup and from new dependencies
- Verification says exactly which tests to write and to show the output
Critique my prompt before I send it#
Here is a prompt I plan to give a coding agent: <paste prompt>. Don't do the task. Instead, list: (1) ambiguities, (2) decisions the agent would have to guess, (3) missing constraints or non-goals, and (4) ways it could technically succeed while being wrong. Then suggest the smallest edits that fix them.
Why it works: It turns a fuzzy worry into a short list of gaps you can fix in a minute, before any code exists.
Restate the task before starting#
Before you start, restate the task in your own words: what you will build, what you will not touch, and what you are assuming. List anything in my request that is ambiguous. Wait for my OK before making changes.
Why it works: A wrong understanding costs one sentence to correct now, and a lot of review time later. Treat the restatement as a check on the agent's understanding, not as proof it will follow it.
Ask what a thin prompt left to chance#
Look at the change you just made. For each choice you made that I did not specify (library, file location, data shape, error handling, naming), list the choice and the alternatives. Mark the ones I should decide.
Why it works: It surfaces the guesses a thin prompt forced, so you can turn them into constraints next time.
Check your understanding#
Check your understanding
Checklist#
- The goal says what and why
- The stack and relevant files are named
- Interfaces and data shapes are defined
- Security and performance rules are concrete, not adjectives
- Non-goals say what not to touch or add
- A verification step names the tests or commands to run
- For anything non-trivial, the agent plans first and I approve
Go deeper#
- Prompting patterns that work: how to run the conversation around the prompt
- Context engineering: what else the agent sees besides your prompt
- Reviewing and verifying AI output: checking what comes back
- Prompt engineering overview (Claude docs)
- Prompt engineering (OpenAI docs)