A few well-chosen input/output examples in the prompt often lock down a format or style more reliably than a longer prose description of the same thing — especially for output shapes that are easy to demonstrate but awkward to describe precisely: a specific tone, a particular level of terseness, a citation style, or a formatting convention with edge cases (how to handle a null field, how to abbreviate a long name, what to do when two categories both apply). Zero-shot prose instructions ask the model to derive the pattern from a description; few-shot examples just show the pattern directly, which is a shorter inferential leap and produces less variance across calls.
Choosing examples deliberately
Three to five examples is typically the useful range for locking in a format — enough to establish the pattern without bloating every request's token count. What matters more than the count is coverage: examples that span the real range of cases teach more than the same number of near-identical easy examples. Concretely, a good few-shot set usually includes:
- One or two typical, unambiguous cases that establish the baseline pattern.
- At least one edge case — a missing field, an unusually long input, a case where two categories could plausibly both apply — because this is exactly where a prose-only instruction tends to leave the model guessing.
- Diverse surface details (different names, numbers, subjects) across examples, so the model generalises the pattern rather than partially memorising incidental content from one example and echoing it into outputs where it doesn't belong.
Delimiting examples from the live input
Wrapping each example clearly — XML-style tags are the standard convention Claude is tuned to recognise — keeps the model from confusing a demonstration with the actual current input, which matters most once a real user query happens to resemble one of the examples closely:
<examples>
<example>
<input>Order #4291 hasn't shipped in 2 weeks</input>
<output>{"category": "shipping_delay", "urgency": "high"}</output>
</example>
<example>
<input>Love the new packaging design!</input>
<output>{"category": "feedback", "urgency": "low"}</output>
</example>
</examples>
<input>{{live customer message}}</input>Without that boundary, an unmarked example sitting in the same block of text as the real task reads to the model as more input to act on, not a demonstration of how to act — it might respond to the example message instead of, or in addition to, the real one.
Combining few-shot with explicit criteria
Few-shot examples and explicit criteria (4.1) solve different problems and stack well together: criteria state the rule in words ("skip style preferences, report bugs and security issues"), examples show what applying that rule actually looks like on real input. Criteria alone can still leave format ambiguous; examples alone can still leave the underlying rule under-specified for cases the examples didn't cover. Put the criteria in the system prompt as the stable, reusable rule, and put the few-shot examples in the user turn near the live input — that keeps the examples close to what they're demonstrating while the system prompt stays a clean, cacheable description of the task.
Order matters: recency effects in example sets
Examples nearer the end of a few-shot block tend to weigh more heavily on the model's output than examples earlier in the same block, particularly when the examples send inconsistent signals. Two practical consequences: don't rely on an early example to override a pattern established by later ones, and when one example is the edge case you most need the model to get right, put it last rather than burying it first. If you're rotating or randomly sampling which examples appear in a prompt across calls, be aware that changing which example lands last will shift observed behaviour even when the total example set is unchanged.
Common exam distractor
An unmarked example sitting in the same block of text as the real task can get treated by the model as part of the actual input rather than a demonstration — tag examples clearly and separately from the live request. "Add more examples" is also a common wrong answer when the actual problem is a lack of delimiting or a lack of diversity among the examples already present; quantity doesn't fix an ambiguity problem that's structural.
Key concept
Few-shot examples work by demonstration, not description — they're most valuable exactly where prose is weakest: pinning down format, tone, and edge-case handling that are easy to show and hard to fully specify in words. Delimit clearly, cover the real range of cases including at least one edge case, and place the case you most need honoured last.