All chapters
  1. Start hereEverything the model reads is text. Only some of it is an instruction
  2. Foundations · 1From a sentence to a prompt: the parts and what each one is for
  3. Foundations · 2Roles and authority: who is allowed to tell the model what to do
  4. Foundations · 3Prompt composition: how an application builds the prompt
  5. Foundations · 4Prompt patterns: five ways to ask, and when each one earns its cost
  6. Surfaces · 5Tool-aware prompting: the tool description is a prompt too
  7. Surfaces · 6MCP prompts and resources: a template you chose versus content that was fetched
  8. Security · 7Prompt injection: when data starts giving orders
  9. Security · 8Defense in depth: assume one layer fails
  10. Operations · 9Long context and prompt placement: where an instruction sits changes what it does
  11. Operations · 10Versioning and provenance: which prompt produced this answer
  12. Operations · 11Testing prompts: golden cases, injection probes and comparisons
  13. Operations · 12Portability: the same prompt on another model is another prompt
  14. Operations · 13Production operations: rolling a prompt out, and rolling it back
  15. Reference · 14Frameworks and tooling: what each one does with your prompt
  16. Reference · 15Advanced topics: other languages, images, hand-offs and attackers who adapt
  17. Reference · 16The insurance lab: one poisoned roof note, end to end
  18. ReferenceGlossary
  19. AboutAbout this site and its sources
Foundations · 4

Prompt patterns: five ways to ask, and when each one earns its cost

Direct instruction, examples, decomposition, self-checking and asking for clarification, each shown on the same case with what it fixes and what it costs.

What you will understand
Five ways to ask
Direct instruction, examples, decomposition, self-checking and asking for clarification: what each one fixes.
What each costs
Tokens, latency and new failure modes: a pattern is a trade, not a free improvement.
When not to
Where code should do the work instead, and why the example computes the rules rather than asking the model to.

Two submissions land on the same afternoon. The first, SUB-1003, is a building whose application leaves the roof age blank; the roof-data provider has no record either. The second, SUB-1004, says the roof is 9 years old; the provider says 22.

Neither case is hard for an underwriter. For the first, you ask the broker for the roof age (rule R-ROOF-02). For the second, the two ages disagree by more than 5 years, so it goes to a senior underwriter (rule R-ROOF-03). But both are easy to get wrong for a model asked in the obvious way, and they go wrong in opposite directions. Asked "what do you recommend?", a model facing a blank roof age has a strong pull to fill it with something typical and carry on. Facing two ages, it has a pull to pick the more official-looking one and move on.

These are cases UW-003 and UW-004. This page is about the handful of ways to ask a model for something, and which of them helps with which failure.

The five patterns, in plain words#

A prompt pattern is a recurring way of structuring the request. Five cover most of what teams use.

Direct instruction. Say exactly what to do, including what to do in the awkward cases. Tiny example: "Never guess a missing value. If a value the rules need is missing, recommend request_info." A prompt that relies on instructions alone, with no examples, is called zero-shot.

Few-shot. Show one or more worked examples of input and answer, so the model can copy the shape and the reasoning. Tiny example: "Worked example: roof_age_years is null and the provider has no record. Answer: request_info, citing R-ROOF-02."

Decomposition. Split one task into smaller steps, each of which is easier to get right. Tiny example: first decide which evidence is needed; then gather it; then apply the rules; then write the recommendation. When each step is its own model call and the output of one becomes the input of the next, the result is called prompt chaining.

Self-check. Ask the model, before it finishes, to check its own answer against stated criteria. Tiny example: "Before you answer, check that every reason that depends on a rule cites the rule id."

Clarifying question. Allow, or require, the model to ask for missing information instead of answering. Tiny example: in this domain the clarifying question is the request_info recommendation, which asks the broker for the roof age or an inspection.

One more term appears in every discussion of patterns. Chain of thought is reasoning the model writes out step by step before its final answer. Tiny example: "The application says 9 years. The provider says 22. They differ by 13, which is more than 5, so R-ROOF-03 applies." Several current models do this internally, in a separate thinking phase, without being asked.

Each pattern on the same two cases#

The insurer's prompt 1.4.0 uses four of the five patterns, each placed where it does one specific job. The table maps them; the sections after it show the evidence.

PatternWhere it is in 1.4.0What it fixes in the exampleWhat it costs
Direct instructionThe never_guess partUW-003: no invented roof ageAbout 30 estimated tokens per call
Few-shotThe example part: one worked request_info caseRules quoted with their text, the next step statedAbout 117 estimated tokens per call; the model copies the example's flaws too
DecompositionThe loop: plan, gather evidence, eligibility in code, then answerUW-004: the rule is computed, not reasonedMore calls and latency in a chain; nothing extra here, because code does one step
Self-checkNot in the prompt; done by code (validate)Wrong or malformed answers never storedDone in the prompt, it adds tokens and a second opinion from the same model
Clarifying questionThe request_info recommendationMissing evidence is asked for, not assumedA slower path for the broker; the right one

Token counts are estimates by tokens.py (illustrative).

Diagram: Where each pattern sits in the agent · prompt patterns, a computed step and a check in code

Read left to right as one run. The prompt carries the direct instruction and the example. The loop decomposes the task and lets code compute the rules. The model explains; code checks; the clarifying-question path asks for what is missing. Click a box to see it on UW-003 or UW-004.

  1. 1 · In the prompt
    1. Direct instruction: One sentence that covers the awkward case: a missing value is requested, not assumed.
    2. Few-shot: A worked example that shows the shape and completeness of a good answer.
  2. 2 · In the loop
    1. Decomposition: The task is split into steps, and the step that can be a function is a function.
  3. 3 · The answer
    1. Model explains: The model turns the computed result and the evidence into reasons a person can read.
    2. Clarifying question: When evidence is missing, the honest answer asks for it, through the underwriter.
  4. 4 · Checked in code
    1. Validation: Code checks the contract, the citations and agreement with the computed result before storing.

Direct instruction: the cheapest fix that can vanish#

For UW-003, one sentence does most of the work. The stand-in model's table has a row for exactly this situation: when the eligibility check lists roof_age_years as missing and the prompt has no "never guess" rule, it assumes a typical roof age of 15 years and recommends approve (row G1). The model here is a scripted stand-in, so these results show how the mechanism works, not how good any model is. The direction is realistic. Filling a gap with a plausible value is what language models are trained to do.

Version 1.3.0 of the prompt removed that sentence while shortening the text. Version 1.4.0 put it back. The two runs, side by side:

cd examples/uw-prompts
python3 run_prompts.py --version 1.3.0 --case UW-003
python3 run_prompts.py --version 1.4.0 --case UW-003
Prompt run · uw-recommend 1.3.0 (trimmed) · hash 2dca80e656a9 · suite UW-003 · model: scripted stand-in (no model called)
case    result  model step    recorded       tokens  failed graders
UW-003  FAIL    approve       request_info      525  recommendation, citations, missing_fields
0 of 1 cases pass · estimated prompt tokens (estimate, not a tokenizer): 525
wrote out/report.json, out/runs/1.3.0/ and out/traces/1.3.0/ (1 run records)
Prompt run · uw-recommend 1.4.0 (restored and ordered) · hash c6bb1887fb1a · suite UW-003 · model: scripted stand-in (no model called)
case    result  model step    recorded       tokens  failed graders
UW-003  pass    request_info  request_info      773  -
1 of 1 cases pass · estimated prompt tokens (estimate, not a tokenizer): 773
wrote out/report.json, out/runs/1.4.0/ and out/traces/1.4.0/ (1 run records)

Under 1.3.0 the stand-in's reasons begin "The roof age is not given, so a typical roof age of 15 years is assumed." The answer is confident (stated confidence 0.9) and invented. The recorded column shows request_info because the application's validator compared the answer with the eligibility check computed in code, found that they disagree, stored the safe value and flagged the run. The prompt pattern failed; the code caught it. That is the order of trust this site keeps returning to.

The lesson about direct instruction is not "add the sentence". It is that an instruction which protects a rare case is the first thing a cleanup removes, because nothing visibly breaks on the common cases. The testing chapter is about catching that.

Few-shot: showing the answer, and its flaws#

The worked example in 1.4.0 is itself a request_info case. The anatomy chapter showed what removing it does in the example: the recommendation stays right and the reasons name rules by id only, without their text (row F2 disappears). That is the typical gain from examples: form, completeness, tone. Anthropic's prompting guide, read today, calls examples "one of the most reliable ways to steer Claude's output format, tone, and structure" and suggests three to five of them.

The cost is subtle. A model tends to copy examples closely. If the only example is a request_info case, a model may over-produce request_info; if the example cites one rule, answers may cite exactly one rule even when two apply. Choose examples that differ from each other, include at least one hard case, and check each example as carefully as code, because an error in it will be repeated.

Decomposition: let code take the step it can do#

UW-004 is a comparison: 9 against 22, more than 5 apart. A model can do that comparison, and it can also get it wrong, choose the wrong rule, or be talked out of it by a confident roof note. The insurer's design does not ask it to. The agent's loop decomposes the task:

  1. Plan. The model names the steps it wants (in the example, the four required tools).
  2. Gather. The application runs the roof assessment, the guidance search and the similar-decision lookup.
  3. Compute. The eligibility rules run in code and produce {"outcome": "escalate", "rules": ["R-ROOF-03"]}.
  4. Explain. The model writes the recommendation from that result, with reasons and citations.

Here is the stand-in's answer for UW-004 under 1.4.0:

{
  "recommendation": "escalate",
  "reasons": [
    "R-ROOF-03: Roof age on the application and from the provider differ by more than 5 years: escalate to a senior underwriter.",
    "Next step: a senior underwriter reviews the case and decides."
  ],
  "citations": ["R-ROOF-03"],
  "missing": [],
  "stated_confidence": 0.8,
  "requires_human": true,
  "policy_version": "2026.2"
}

The model recommends; a person decides. And in this design the model also does not compute: the rule was applied by code, so the same input always gives the same eligibility result. The model's job is the part it is good at: turning a result and its evidence into reasons a person can read.

That is the strongest form of decomposition, and it is worth saying as a rule: when a step can be written as a function, write the function. Prompt chaining, where every step is a model call, is the right tool when every step needs language: summarize a long document, then classify the summary, then draft a letter. Anthropic's guide read today says explicit chaining "is still useful when you need to inspect intermediate outputs or enforce a specific pipeline structure."

For a backend engineer. Decomposition is the same move as breaking a stored procedure into services with clear contracts, and the same trade: each boundary adds latency and a place to fail, and buys you a place to log, test and retry. The difference is that each model step is probabilistic, so errors compound along a chain. Three steps that are each right 95 percent of the time (illustrative numbers) are all right together less often than any one of them. Put deterministic steps in code and keep model steps few.

Self-check: useful, and still the same model#

Asking a model to review its own answer before finishing catches some errors: a missing citation, a field left out, arithmetic slips. Anthropic's guide read today suggests appending something like "Before you finish, verify your answer against [test criteria]", and notes an exception for one current model, where carried-over verification instructions "can cause over-verification, adding tokens and latency." So even this advice is model-specific and dated.

The limit is structural. The checker is the same model, reading the same prompt, including any injected text. A self-check cannot catch an error that the model does not believe is an error. In the example, checking is done by code instead: agent_sim.py, function validate, checks that the answer is the contracted JSON, that every citation is a real rule, that requires_human is true, and that the recommendation agrees with the eligibility result. A model self-check, where you use one, sits before that, never instead of it.

Clarifying question: the answer that admits it does not know#

In a chat product, a clarifying question goes back to the user. In this agent, the person who knows the roof age is not the underwriter but the applicant, through the broker. So the clarifying question takes the form of a recommendation: request_info, with missing: ["roof_age_years"] and a next step that says what to ask for. The underwriter decides whether to send it.

Making that path explicit matters more than any wording. A prompt that lists only approve and decline has removed the honest answer, and a model under pressure to produce one of two will produce one of two.

What this is not. Patterns are ways of asking. Measuring whether a pattern improves results across many cases and trials, with graders and statistics, is evaluation, the subject of eval.sammuthu.com. This chapter shows mechanisms on single cases; it does not claim a pattern is better in general.

Try it: remove a pattern#

The parts lab composes prompt 1.4.0 with any of five parts switched off. The example part is the few-shot pattern. The instruction part includes the never_guess sentence. Set the case to UW-003, switch the instruction off and on, then the example, and compare the stand-in's answer with the expected one.

Part switched off on UW-003What the stand-in's answer loses
Instruction (with never_guess)No recommendation at all: a summary of the input
DataAsks for the whole submission
Example (the few-shot pattern)Rules named by id only, not quoted
Output formatProse that code cannot read
Success criteriaNo rule ids cited
The same idea for a coding agent. A coding agent asked to "fix the bug" in one step often edits the test instead of the code. Decomposed, the task becomes: reproduce the failure, write down the cause, change the code, run the tests. The test run is the coding agent's computed step: a fact produced by code, not by the model's opinion. A clarifying question matters there too: an agent that may stop and ask "which of these two behaviors is intended?" produces fewer confident wrong pull requests. How teams wire those steps into review and CI is the subject of diff-to-deploy.sammuthu.com.
Deeper: chain of thought, thinking models and what to log

Asking a model to "think step by step" was, for a while, the most quoted prompt pattern. Current models change the picture in two ways read today in Anthropic's guide:

  • Many models now reason in a separate thinking phase. The guide describes manual chain-of-thought prompting as "a fallback" when thinking is off, and says that on several current models a prompt that asks the model to write out its reasoning in tags "might be declined"; it recommends relying on thinking instead.
  • Worked examples still shape that internal reasoning: the guide says multishot examples "shape how Claude approaches similar problems in its own thinking blocks."

For a regulated workflow the practical question is what to keep. Written-out reasoning is not an audit trail: it is text the model produced, which may not reflect how the answer was reached, and it can contain the injected text verbatim. The example's run record keeps facts instead: which tools ran, the eligibility result computed by code, the evidence ids, the prompt version and hash, and the person's decision. Reasons in the recommendation are for the underwriter to read, and they cite rule ids that code has checked.

Deeper: what patterns cost, measured the only way that counts

Every pattern adds tokens to every call or adds calls to every task. In the example, the instruction and example parts together are about 147 estimated tokens out of roughly 775 on UW-004, and they are static, so a provider's prompt caching can reuse them (see long-context). A three-step chain would roughly triple the calls and add their latencies in sequence.

The way to decide is the same for every pattern: run the golden cases with and without it, and look at which cases change. If nothing changes on any case, either the pattern is not needed or the cases do not cover what it protects. The 1.2.0 to 1.3.0 comparison in the example is the cautionary tale: 393 fewer estimated tokens on the smoke suite, and UW-003 broke. The testing chapter runs that comparison.

Deeper: competing designs for the same two cases

Three serious designs exist for cases like UW-003 and UW-004, and each has a place.

  • Model computes, prompt instructs. All rules in the prompt; the model applies them. Simple to build, flexible with fuzzy rules, and the least predictable. Acceptable for advice that a person always reviews closely, and weakest under injection.
  • Code computes, model explains. The example's design. Deterministic where the policy is crisp, auditable, robust to injected text in the rule step. It needs the rules to be codable, and it moves the hard work to keeping code and written guidance in step.
  • Model extracts, code decides. The model's only job is to turn free text (a roof note, an inspection report) into typed facts; code applies the rules. Strong against injection because the model's output has no field that can carry an instruction. The defense chapter calls a separate reader of this kind a quarantined reader, and the example has one (compose.py, function quarantine_extract).

Most production systems end up mixing the last two: code for every rule that can be written down, a model for language, and a person for the decision.

Checklist: choosing a pattern#

QuestionIf yes
Is there a case where information may be missing?Direct instruction for it, and a clarifying-question path in the output
Is the answer's form or completeness inconsistent?Add two to five varied examples; check each one
Can a step be written as a function?Write the function; give the model its result
Do steps need language and need to be inspected separately?Chain them, and log each step's output
Do you want a self-check?Keep it, and validate in code after it
Does the pattern earn its tokens?Prove it on the golden cases, with and without

In one breath#

There are five common ways to ask: a direct instruction, worked examples, splitting the task into steps, a self-check, and permission to ask for what is missing. Each one fixes a specific failure and costs tokens, calls or new risks: an instruction that protects a rare case gets deleted in a cleanup, an example gets copied with its flaws, a chain compounds errors, and a self-check is the same model grading itself. The strongest move is to take every step that can be computed out of the prompt and into code, and leave the model the language.

So far the model has only written text. The next chapter gives it tools to call, and shows that a tool's name, description and schema are prompt text too. Continue to tools.