---
title: Prompting patterns that work
summary: Reusable moves for steering an agent, such as plan first, show diverse examples, ask for pushback and work in small verified steps.
section: ai
phase: any
order: 3
last_reviewed: 2026-11-20
---

# Prompting patterns that work

[Anatomy of a good prompt](/docs/start-here/anatomy-of-a-good-prompt.md) tells you what a prompt contains. This page is about how you run the conversation: a handful of patterns that improve results on almost any task.

## You'll be able to

- Get a plan you can correct before any code is written
- Use examples that teach the pattern instead of causing the agent to overfit
- Invite pushback so you hear about problems early
- Break a big task into small steps that each end with proof

## The mental model

A prompt is the start of a loop, not a single throw. The agent proposes, you check, you steer. The patterns below are ways to make each pass of that loop cheaper and more informative: cheaper to correct (plans before code), clearer to steer (examples, reasons), and easier to trust (verification built in).

## Key concepts

- **Explain the why:** A rule with a reason generalizes better than a bare rule. "Store prices as integer cents because we sum them and floats drift" lets the agent handle cases you never mentioned. Anthropic's prompting guidance gives this advice directly.
- **Plan, then act:** Ask for a short plan first and approve it. OpenAI's guidance for agentic work likewise suggests having the agent plan before tool calls and keep going until the task is resolved.
- **Few-shot examples:** Show a few input and output examples. Anthropic suggests roughly three to five, and both Anthropic and OpenAI stress variety so the model doesn't latch onto an accidental pattern.
- **Separate instructions from data:** Use headings or tags (like `<data>...</data>`) to mark what is instruction and what is material to work on. Put long documents before the question, and consider asking the model to quote the relevant parts first.
- **Action versus advice:** "Suggest changes" gets suggestions. "Make this change" gets edits. Say which you want.
- **Pushback on request:** Ask the agent to question your approach and raise ambiguities before it builds.
- **Verification built in:** Give a way to check the result (tests, a command, an expected output) and ask the agent to run it. This is the most reliable lever you have.
- **Small steps with checkpoints:** For long tasks, work in stages, keep progress notes in a file, and commit to git at each good state so you can step back.

## Decisions you make (not the agent)

| Decision | Sensible default | Choose otherwise when… |
|---|---|---|
| Plan first or build directly | Plan first for anything touching more than a file or two | The change is tiny and obvious |
| How many examples | Three to five that differ from each other, including edge cases | One example is enough only when the format is trivial |
| Rule wording | Say what to do, with a reason | A hard safety rule: state it plainly once, don't shout it repeatedly |
| Advice or edits | Say explicitly: "make the change" or "propose only" | You are exploring: ask for options and no edits |
| Step size | One reviewable step per prompt, each ending with a check | The work is mechanical and well covered by tests |
| Ask for questions first | Yes when requirements are fuzzy | The spec is fully nailed down |
| Reasoning depth | Ask for a plan or explanation where the choice is non-obvious | Simple, well-defined edits |

## What good output looks like

- A plan you can approve or correct before code exists
- Questions about real ambiguities, not filler
- Behavior that matches your examples and also handles inputs you didn't show
- Small diffs, each with its checks run and reported
- Honest status: what was done, what wasn't, what was assumed

## Red flags

- **Aggressive wording everywhere** ("MUST", "NEVER", all caps) → Anthropic's guidance notes that forceful wording (for example, "MUST use this tool") can make newer models over-trigger. Use calm, specific instructions with reasons.
- **Examples that are all alike** → the agent copies the pattern, not the rule. Add edge cases.
- **"Suggest" when you wanted edits** (or the reverse) → you get the wrong kind of output. State which you want.
- **Code that special-cases your test or example** → ask for a general solution, and add different test inputs.
- **Giant prompts that bundle five tasks** → split them. Review is easier, and so is rollback.
- **No checkpoint** → one bad step buries a good one. Commit after each verified stage.
- **The agent just agrees with everything** → explicitly ask it to challenge the approach.

## Worked example

**Task:** Add a "download bookings as CSV" feature to a Next.js app with Postgres and Drizzle.

You send a short prompt with one example row: `2026-03-01,Jane Doe,Haircut,45`. The agent produces an endpoint that joins values with commas, matching your example exactly. Tests pass on that example.

**What a good result contains:** correct quoting and escaping of fields, a header row, a stable column order, streaming or pagination for large exports, and tests with awkward inputs.

**The wrong turn:** a customer named `Smith, Jane` or a service note containing a quote or a newline breaks the file. The agent matched your single example and never saw the edge cases, so it had no reason to handle them.

**How review catches it:** ask the agent to generate five awkward rows (commas, quotes, a newline, accented characters, an empty field) and show the output for each. Then add those rows as tests and ask for a general solution that handles them, not a patch for the one that failed. Next time, put the diverse examples in the original prompt.

## Sample prompts

### Weak vs strong
```compare
## Weak
Add a CSV export for bookings.
## Why it fails
No columns, no format rules, no example, and no way to verify. The agent decides everything.
## Strong
Goal: add GET /api/bookings/export that downloads the current user's bookings as CSV.
Stack: Next.js (App Router), TypeScript, Postgres via Drizzle.
Columns, in order: date (ISO), customer name, service, price in dollars.
Constraints: use standard CSV quoting (quote fields containing commas, quotes or newlines; double any inner quotes); header row first; only the signed-in user's rows; stream the response so large exports don't load everything into memory.
Examples (all must work):
- 2026-03-01,Jane Doe,Haircut,45.00
- 2026-03-02,"Smith, Jane",Colour,120.50
- 2026-03-03,"O""Neil",Trim,30.00
- 2026-03-04,Zoë Müller,"Cut
and style",60.00
Non-goals: no UI changes, no new dependencies.
Verify: add tests for each example plus an empty field; run lint, typecheck and tests and show the output.
## Why it works
Diverse examples teach the rule (quoting), the constraints say how, and the verify step proves it.
## What changed
- **Columns and format** are specified, instead of left to the agent
- **Diverse examples** include a comma, a quote, an accented name and a newline
- **Constraints** name standard CSV quoting and streaming for large exports
- **Verify** requires a test for each example, plus an empty field
```

### Plan first
```text
Don't write code yet. Propose a plan for this task in 6 steps or fewer: the files you will touch, the order, and how you will verify each step. Flag anything you are unsure about. I will approve or change the plan before you start.
```
*Why it works:* A wrong plan costs a minute to fix. Wrong code costs a review.

### Ask for pushback and questions
```text
Before you build anything, tell me (1) what is ambiguous or missing in this request, as a short list of questions, and (2) any part of my approach you would do differently and why. Wait for my answers.
```
*Why it works:* It surfaces assumptions while they are cheap to fix, and it gives the agent permission to disagree.

### Generate the edge cases
```text
Here are 3 example inputs and outputs: <paste>. Generate 5 more inputs that are different from these and likely to break a naive implementation (empty values, special characters, very long values, unusual formats). Show the expected output for each, and tell me which expectations you are unsure of.
```
*Why it works:* Asking for diversity on purpose fixes the "all examples alike" problem. Check the expected outputs yourself.

### Work in a checkpointed step
```text
Do only step 1 of the plan. Run the tests, then show me the diff and the test output. If everything passes, commit with a clear message and stop. Do not start step 2 until I say so.
```
*Why it works:* Each step is small enough to review and leaves a safe commit to return to.

### Explain the reason, then ask for edits
```text
Make the change directly (don't just suggest it): store money as integer cents in the database and convert to dollars only when displaying. Reason: we sum amounts across many rows and floating-point rounding errors add up. Apply this to the bookings table and every place that reads or writes price.
```
*Why it works:* It says "make the change", and the reason lets the agent handle places you didn't list.

## Check your understanding

```quiz
Q: You want the agent to edit a file. Which wording is better?
- [ ] "Suggest changes to this file"
- [x] "Make this change to the file"
- [ ] "Could the file be improved?"
> Why: Suggest-style wording gets suggestions. Say which you want, edits or advice.

---

Q: Why should few-shot examples differ from each other?
- [ ] To make the prompt longer
- [x] So the model learns the rule, not an accidental pattern from near-identical examples
- [ ] Because the model ignores the first example
> Why: Both Anthropic's and OpenAI's guidance stress varied examples, including edge cases.

---

Q: What is the main benefit of asking for a plan before any code?
- [ ] The agent works faster
- [x] A wrong plan is cheap to correct, and a wrong implementation is expensive to review
- [ ] Plans are required by the model
> Why: Approving a plan first keeps you in control of the approach before work piles up.
```

## Checklist

- [ ] Planned before building anything non-trivial
- [ ] Examples differ from each other and include edge cases
- [ ] Each important rule has a reason
- [ ] Stated whether I want edits or suggestions
- [ ] Each step ends with a check and a commit
- [ ] Asked the agent for questions and pushback at least once

## Go deeper

- [Prompting best practices (Claude docs)](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/be-clear-and-direct): being specific, giving reasons, examples, structure and agentic tips
- [Prompt engineering overview (Claude docs)](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/overview): define success criteria and a way to test before tuning prompts
- [Prompt engineering (OpenAI docs)](https://developers.openai.com/api/docs/guides/prompt-engineering): message roles, structure, few-shot examples, caching and agentic guidance
- [Anatomy of a good prompt](/docs/start-here/anatomy-of-a-good-prompt.md): the six parts of a strong prompt
- [Context engineering](/docs/ai-agents/context-engineering.md): what else goes in the window
- [How LLMs work, for builders](/docs/ai-agents/how-llms-work.md): why outputs vary and models guess
