---
title: Anatomy of a good prompt
summary: The six parts of a prompt that gets production-sane code on the first try.
section: start-here
phase: any
order: 3
last_reviewed: 2026-11-20
---

# 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 agent 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.

```prompt-builder
title: Build a strong prompt
field: goal | Goal: what should it do, and why? | Users can reset their password by email
field: context | Context: stack, versions, relevant files | Next.js 15 (App Router), TypeScript, Drizzle + Postgres
field: interfaces | Interfaces: inputs, outputs, routes, data shapes | POST /api/auth/forgot with { email }, always returns 200 | multiline
field: constraints | Constraints: security, performance, conventions | Tokens expire in 30 minutes and can be used once | multiline
field: nongoals | Non-goals: what not to touch or add | Don't change the login page; no new dependencies
field: verification | Verification: tests to write, commands that must pass | Tests for valid, expired and reused tokens; run tests and type-check | multiline
option: plan | Ask the agent to plan first | Plan first and wait for approval before implementing. | checked
preset: Password reset
  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\n- /reset-password?token=… page: new password + confirm → POST /api/auth/reset
  constraints: - Forgot endpoint always returns 200 (don't reveal whether an email exists)\n- Token: 32+ random bytes, store only a SHA-256 hash, expires in 30 min, single use\n- Rate limit forgot endpoint to 5 requests/hour per IP and per email\n- Hash passwords with the existing helper in lib/auth/password.ts
  nongoals: 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.
preset: CSV export
  goal: Add GET /api/bookings/export that downloads the current user's bookings as CSV.
  context: Next.js (App Router), TypeScript, Postgres via Drizzle.
  interfaces: Columns, in order: date (ISO), customer name, service, price in dollars.
  constraints: - Use standard CSV quoting (quote fields containing commas, quotes or newlines; double inner quotes)\n- Header row first\n- Only the signed-in user's rows\n- Stream the response so large exports don't load everything into memory
  nongoals: No UI changes, no new dependencies.
  verification: Add tests for a comma, a quote, a newline, an accented name and an empty field. Run lint, typecheck and tests and show me the output.
template:
Goal: {goal}
Context: {context}
Interfaces: {interfaces}
Constraints: {constraints}
Non-goals: {nongoals}
Verification: {verification}
{plan}
```

## Key concepts
- **Specificity where it matters:** Pin down things that are expensive to change later (data models, API 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)

| 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 verification step, 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 Non-goal 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
```compare
## Weak
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.
## Strong
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
```text
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
```text
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
```text
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

```quiz
Q: Which part of a prompt tells the agent what NOT to change or add?
- [ ] Context
- [ ] Interfaces
- [x] Non-goals
- [ ] Verification
> Why: Non-goals are the boundary. Without them, agents tend to "helpfully" touch login pages, add dependencies or reformat unrelated files.

---

Q: A prompt says "make it secure". What is the best fix?
- [ ] Repeat it in capital letters
- [x] Replace it with specific rules (for example token expiry, hashing, rate limits) the agent can implement and you can check
- [ ] Remove it and let the agent decide
> Why: An adjective has no criteria. Concrete constraints can be built and verified.

---

Q: Which of these is a verification step?
- [ ] "Make sure it works"
- [x] "Write tests for valid, expired and reused tokens, run them, and show me the output"
- [ ] "Use best practices"
> Why: A verification step names the evidence you want to see. The other two can't be checked.
```

## 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](/docs/ai-agents/prompting-patterns.md): how to run the conversation around the prompt
- [Context engineering](/docs/ai-agents/context-engineering.md): what else the agent sees besides your prompt
- [Reviewing and verifying AI output](/docs/ai-agents/reviewing-ai-output.md): checking what comes back
- [Prompt engineering overview (Claude docs)](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/overview)
- [Prompt engineering (OpenAI docs)](https://developers.openai.com/api/docs/guides/prompt-engineering)
