Few-shot prompting with Claude: how many examples, which ones, and how to format them
Few-shot prompting means showing the model a few worked examples of the task inside the prompt, so it copies the format and the judgment instead of guessing from instructions alone. Anthropic's current guidance is 3 to 5 examples that are relevant, diverse and wrapped in example tags. The examples that pay off most are the hard, ambiguous cases, with the reason for each answer.
What is few-shot prompting?
Few-shot prompting (also called multishot prompting) means including a few worked examples of the task in your prompt: an input, and the output you want for it. Zero-shot is the same prompt with no examples. Anthropic's prompting guide calls examples "one of the most reliable ways to steer Claude's output format, tone, and structure", and says a few well-crafted ones improve accuracy and consistency.
Instructions tell the model what you want; examples show it. When the instructions are already clear and the output still comes back in five different shapes, examples are usually the fix.
How many examples for few-shot prompting?
The current docs say: "Include 3–5 examples for best results." The Claude Certified Architect exam guide (task 4.2) talks about 2 to 4 targeted examples. Both point the same way: a handful of well-chosen examples, not a long list. More examples cost tokens on every request and, if they are similar, add nothing.
Make the examples relevant, diverse and structured
The prompting guide gives three rules:
- Relevant: mirror your real use case closely. Examples about movie reviews won't teach a support-ticket classifier much.
- Diverse: cover edge cases and vary enough that Claude doesn't pick up unintended patterns.
- Structured: wrap each example in
<example>tags, and the set in<examples>tags, so Claude can tell them apart from the instructions.
You can also ask Claude to review your examples for relevance and diversity, or to draft more from your first set.
Aim your examples at the hard cases
Easy cases rarely need an example; the model gets them right anyway. The value is in the ambiguous ones, and in showing why one answer beats the plausible alternative. Here is a triage prompt for a bike-rental support inbox:
```xml Classify each customer message as REFUND, DAMAGE, BOOKING or OTHER.
Message: {{message}} ```
Two of the three examples are borderline on purpose, and each says why. That teaches the model a rule it can apply to messages you never listed, which is what the exam guide means by letting the model "generalize judgment to novel patterns rather than matching only pre-specified cases".
Common few-shot prompting mistakes
- Accidental patterns. All examples are short, or all end in the same label, or all start with "Hi": the model copies that too. Vary everything except what you want copied.
- Examples that contradict the instructions. If the instructions say "one word" and an example writes a sentence, expect sentences.
- Only easy cases. They make the prompt longer and the hard cases no better.
- Examples instead of criteria. If you can state the rule ("flag a comment only when it contradicts what the code does"), state it. Examples then show how the rule applies at the edges.
Few-shot prompting for extraction and structured output
Examples also help when you pull data out of messy documents. Show one document that has the field in an unusual place and one where the field is truly absent, with null in the output. The model learns to look harder before giving up, and to return null instead of inventing a value. Combined with a JSON schema through tool use or structured outputs, examples fix the format while the schema enforces it.
Few-shot examples and extended thinking
With thinking turned on, examples still work: worked examples "shape how Claude approaches similar problems in its own thinking blocks". The guide suggests presenting each as the problem, the method to apply and the expected answer.
Few-shot prompting on the Claude Certified Architect exam
Domain 4 (Prompt Engineering & Structured Output) is 20% of the CCAR-F exam. Task 4.2 expects you to reach for few-shot examples when detailed instructions alone give inconsistent output, to target ambiguous cases with the reasoning shown, and to use examples to cut false positives and empty extractions. Task 4.1 is its partner: explicit criteria beat vague instructions such as "be conservative" or "only report high-confidence findings".
The trap: when output is inconsistent, the tempting answer is "add more instructions" or "tell it to be careful". The expected answer is targeted examples, built on explicit criteria.
Related: the Claude API basics and all articles.
Sources: Prompting best practices (use examples effectively; be clear and direct; thinking); Claude Certified Architect Foundations exam guide v1.0, task statements 4.1 and 4.2.
FAQ
What is few-shot prompting?
Putting a few input and output examples of the task in the prompt so the model follows their format and judgment. It is also called multishot prompting; zero-shot means no examples at all.
How many examples should a few-shot prompt have?
Claude's prompting guide recommends 3 to 5 examples for best results. The Claude Certified Architect exam guide speaks of 2 to 4 targeted examples. Both agree that a few well-chosen examples beat many similar ones.
How should I format few-shot examples for Claude?
Wrap each one in example tags and the set in examples tags, so Claude can tell them apart from your instructions and from the real input.
Why does my few-shot prompt give the wrong pattern?
Usually because the examples share something you didn't intend, such as the same length, the same label or the same opening. Vary them so the only thing they have in common is what you want copied.