Overview
Every prompt mixes rules, which the model should always follow, with examples, which it should generalize from. Few-shot prompting is the example half. Anthropic calls examples one of the most reliable ways to steer output format, tone, and structure; the cost is input tokens on every call, so each example must earn its slot. The guidance applies to Claude, GPT, and Gemini models alike.
Use examples when the rule is easier to show than to say
Reach for examples when tone, layout, an idiosyncratic format, or the boundary between two similar categories resists description. A page of prose describing a tone loses to three samples of it. Skip examples when one sentence states the rule and the model already follows it (“write a summary”).
Use rules for hard, universal constraints
A rule applies to every input; an example applies to inputs that look like it. Safety refusals, “return JSON only”, “never echo the password”, and required schema fields are rules, and they live in the system prompt (system-prompts).
Write three to five relevant, diverse, tagged examples
Anthropic recommends three to five examples that mirror the real use case, vary enough that the model does not copy an accident, and sit in <example> tags (many in <examples>) so they cannot be mistaken for instructions. Use the same labels in the live prompt.
<examples>
<example>
<input>Refund my order #401.</input>
<output>{"intent": "refund_request", "order_id": "401"}</output>
</example>
<example>
<input>How do refunds work?</input>
<output>{"intent": "policy_question", "order_id": null}</output>
</example>
</examples>- Cover the easy case, an edge case, and an adversarial case; vary length, vocabulary, and structure. For multi-class classification, include at least one example per class.
- If three examples look alike, keep one. Test: shuffle the set and read only the inputs; an example whose output you can guess from a sibling is redundant.
- If a task seems to need twenty examples, consider fine-tuning or retrieving examples per request instead.
- With Claude thinking enabled,
<thinking>tags inside examples show the reasoning pattern the model should follow.
Include negative examples at the boundary
A negative example looks like one category but belongs to another. The second row above is one: it mentions refunds yet is a policy question. Without it the model collapses both into refund_request. Negatives teach the boundary; positives teach the interior. Do the same for format (an input where the model’s default layout is wrong) and for safety (an innocently framed harmful request that must be refused).
Make examples obey the rules
An example that violates a rule teaches the violation. Audit every example against the rule list before adding it. If the model breaks a rule on inputs that resemble an example, the example is overriding the rule; fix or replace the example. Order can also change results, so try two or three orderings in the eval set instead of assuming the last example dominates.
Combine them: the rule is the ceiling, examples fill the shape
Rules:
- Return one of: approve, request_changes, block.
- Block if the migration drops a column or table.
Examples: <example> ALTER TABLE users DROP COLUMN email;
-> {"verdict": "block", "reasons": ["drops a column"]} </example>Rules define the boundary; examples teach how to fill the discretionary space inside it.
Rebalance with evals, not intuition
Prompts accumulate rules and examples one bug fix at a time. Two refactoring signals:
- A rule longer than a sentence or two (“format dates as YYYY-MM-DD except in fiscal contexts where…”) is a demonstration in disguise; replace it with one example per context.
- A growing pile of examples that each patch one edge case probably wants a single rule that covers them.
Then measure: run the eval set rules-only, examples-only, and combined (prompt-evals). The lift of the combined prompt over the better single tells you whether the examples earn their tokens. Drop any example whose removal does not move the score, and if zero-shot scores within noise of few-shot, ship zero-shot.