What you will be able to do
- Recognise when few-shot examples are the right fix for inconsistent output that detailed instructions have not solved
- Build a small example set that is relevant, diverse and wrapped in tags
- Use an example to fix the exact shape of each output, such as a review finding with location, issue, severity and suggested fix
- Explain how a few examples let Claude generalise to inputs that none of them show
Key concept
Few-shot (multishot) prompting — You put a small number of finished input/output examples in the prompt. Claude copies their format, structure and judgement, which steers output more reliably than describing those things in words.
1.When instructions alone stop working
Say you have written careful instructions for a code reviewer or an extraction pipeline, and the output still drifts. One run lists findings as bullets, the next writes paragraphs, and a third leaves out severity. Adding more adjectives to the instructions rarely fixes this. Anthropic's prompting guide says it plainly: examples are one of the most reliable ways to steer Claude's output format, tone and structure. A few well-crafted ones improve both accuracy and consistency. The technique is called few-shot or multishot prompting.
Anthropic's prompt-engineering blog lists four reasons to reach for examples. The format may be easier to show than to describe. You may need a specific tone or style. The task may involve subtle patterns or conventions. Or simple instructions haven't produced consistent results. Exam scenarios usually describe that last case: the team has already written detailed instructions and the output is still inconsistent. The cookbook on generating test cases goes further. It calls giving Claude examples 'perhaps the best way to improve its performance', and says realistic inputs are half the work of building ideal input/output pairs.
Examples don't replace instructions. The same guide still tells you to be specific about the output format and constraints, and to explain why a constraint matters. Examples add the one thing prose struggles to pin down: what a finished answer actually looks like.
Checkpoint 1 of 4· Check yourself
A team's prompt already has two paragraphs of formatting rules, but the output structure still varies from run to run. According to Anthropic's guidance, which change is most likely to make the output consistent?
Inconsistent results despite simple instructions is exactly when the guidance says to use examples, which are among the most reliable ways to steer format.
“Examples are one of the most reliable ways to steer Claude's output format, tone, and structure.”Source: platform.claude.com
2.Relevant, diverse, structured, and few
The prompting guide gives three properties that a useful example set needs. Each one prevents a particular failure.
| Property | What the guide asks for | Failure it prevents |
|---|---|---|
| Relevant | Mirror your actual use case closely | Claude learns a format or judgement that doesn't fit your real inputs |
| Diverse | Cover edge cases and vary enough to avoid unintended patterns | Claude copies an incidental feature that all the examples happen to share |
| Structured | Wrap each example in <example> tags, and the set in <examples> | Claude mistakes example content for instructions |
Diversity does not mean volume. Anthropic's post on context engineering warns about a common habit: teams stuff a laundry list of edge cases into a prompt, trying to spell out every possible rule. Its advice is to curate a set of diverse, canonical examples that show the expected behaviour. In its words, examples are the 'pictures' worth a thousand words. The prompt-engineering blog's tip points the same way: start with one example, and add more only if the output still doesn't match what you need. For examples inside tool definitions, Anthropic's advanced tool use post suggests one to five per tool, built from realistic data rather than placeholders like "string" or "value".
Checkpoint 2 of 4· Match them up
Match each piece of example-design guidance to what it is for
Tap a term, then the definition that fits it.
The guide names relevant, diverse and structured as the three properties. The context-engineering post adds that the set should be curated and canonical rather than exhaustive.
“Diverse: Cover edge cases and vary enough that Claude doesn't pick up unintended patterns.”Source: platform.claude.com
3.Showing the exact shape of each output
Anthropic's page on output consistency lists 'constraining with examples' as one of its main techniques. Its market-intelligence example shows how this works. The prompt gives Claude a single filled-in template for a made-up company, says 'Output following this example format', and then asks for two real competitors. Both answers come back with the same tags, the same SWOT breakdown and the same short strategy line.
<competitor>
<name>Rival Inc</name>
<overview>A 50-word summary.</overview>
<swot>
<strengths>- Bullet points</strengths>
<weaknesses>- Bullet points</weaknesses>
<opportunities>- Bullet points</opportunities>
<threats>- Bullet points</threats>
</swot>
<strategy>A 30-word strategic response.</strategy>
</competitor>The template also sets lengths ('A 50-word summary', 'A 30-word strategic response'). That is detail a format description often leaves out. You can apply the same move to a code reviewer that reports findings inconsistently. Write two or three example findings, each with the same fields: location, issue, severity and suggested fix. The sources don't show this particular schema, but the mechanism is the one the guide demonstrates. Claude reproduces the fields, their order and their level of detail because it has seen a finished answer.
The summarization cookbook shows how strongly Claude picks up format. The authors added three example summaries to a prompt without saying anything about format, and the new summary came back in the examples' sectioned layout. In their words, they didn't explicitly tell Claude to follow the format of the examples, but it seems to have picked up on it anyway.
Checkpoint 3 of 4· Check yourself
A code-review agent sometimes gives a line number, sometimes a severity, and rarely a fix. Which prompt change most directly makes every finding come back in the same actionable form?
The consistency guide constrains output by showing a complete example of the format. Vague adjectives and long category lists don't show the shape of an answer.
“Make Claude's outputs more consistent by specifying exact formats, prefilling responses, constraining with examples, and grounding answers in retrieval.”Source: platform.claude.com
4.Generalising beyond the examples shown
Examples are not a lookup table. Claude works out the pattern behind them and applies it to inputs none of them covered. The prompting guide says the same about explanations: Claude is smart enough to generalise from the reason behind a rule. Examples give it something concrete to generalise from.
Anthropic's advanced tool use post shows how much an example set can teach without stating any rules. It gives three sample calls to a create_ticket tool: a critical bug, a feature request, and a title-only internal task. From these, Claude learns the date and ID formats. It also learns correlations that no schema states: critical bugs have full contact info and escalation with tight SLAs, while internal tasks have a title only. In Anthropic's internal testing, these examples raised accuracy from 72% to 90% on complex parameter handling.
The same ability can work against you, which is why the guide asks for diversity. If every example shares an incidental feature, such as the same length or the same kind of input, Claude may treat that feature as part of the pattern. Vary whatever shouldn't matter, so that only the intended judgement stays constant.
Checkpoint 4 of 4· Check yourself
Three create_ticket examples never state a rule about when to include escalation details. According to Anthropic's post, what does Claude learn from them?
The post lists optional-parameter correlations among the things Claude infers from the three examples, even though no explicit rule is given.
“Critical bugs have full contact info + escalation with tight SLAs”Source: www.anthropic.com
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.The most reliable prompt lists every edge case and rule you can think of.Why is that wrong?
Anthropic advises against laundry lists of edge cases. It recommends a small, curated set of diverse, canonical examples that show the expected behaviour.
Covered in Relevant, diverse, structured, and few
2.Few-shot examples only help with inputs that closely match one of the examples.Why is that wrong?
Claude infers the pattern behind the examples and applies it to new inputs. That is why a few diverse examples are enough.
Covered in Generalising beyond the examples shown
Sources
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practicesOfficial docs
“Examples are one of the most reliable ways to steer Claude's output format, tone, and structure.”
↩︎ When instructions alone stop working“Structured: Wrap examples in <example> tags (multiple examples in <examples> tags) so Claude can distinguish them from instructions.”
↩︎ Relevant, diverse, structured, and few“Claude is smart enough to generalize from the explanation.”
↩︎ Generalising beyond the examples shown“A few well-crafted examples (known as few-shot or multishot prompting) improve accuracy and consistency.”
↩︎ Key concept“Diverse: Cover edge cases and vary enough that Claude doesn't pick up unintended patterns.”
↩︎ Checkpoint - 2.https://claude.com/blog/best-practices-for-prompt-engineeringSecondary source
“Simple instructions haven't produced consistent results”
↩︎ When instructions alone stop working“Start with one example (one-shot). Only add more examples (few-shot) if the output still doesn't match your needs.”
↩︎ Relevant, diverse, structured, and few - 3.https://platform.claude.com/cookbook/misc-generate-test-casesSecondary source
“Giving Claude examples is perhaps the best way to improve its performance.”
↩︎ When instructions alone stop working - 4.
“teams will often stuff a laundry list of edge cases into a prompt in an attempt to articulate every possible rule”
↩︎ Relevant, diverse, structured, and few“we recommend working to curate a set of diverse, canonical examples that effectively portray the expected behavior of the agent.”
↩︎ Exam trap 1 - 5.https://platform.claude.com/docs/en/test-and-evaluate/strengthen-guardrails/increase-consistencyOfficial docs
“Output following this example format:”
↩︎ Showing the exact shape of each output“Make Claude's outputs more consistent by specifying exact formats, prefilling responses, constraining with examples, and grounding answers in retrieval.”
↩︎ Checkpoint - 6.
“we didn't explicitly tell Claude to follow the format of the examples, but it seems to have picked up on it anyway.”
↩︎ Showing the exact shape of each output“This illustrates the power of few-shot learning, and how Claude can generalize from a few examples to new inputs.”
↩︎ Generalising beyond the examples shown“This illustrates the power of few-shot learning, and how Claude can generalize from a few examples to new inputs.”
↩︎ Exam trap 2 - 7.https://www.anthropic.com/engineering/advanced-tool-useSecondary source
“In our own internal testing, tool use examples improved accuracy from 72% to 90% on complex parameter handling.”
↩︎ Generalising beyond the examples shown“Critical bugs have full contact info + escalation with tight SLAs”
↩︎ Checkpoint