D4 · Prompt Engineering › Cluster 3 · Examples (Multishot)

3.2 · How Many Examples & Choosing Them

3–5 relevant, diverse examples

CONCEPT A few, chosen for relevance and diversity

Anthropic's guidance is specific: include 3–5 examples for best results, and scale up for more complex tasks. The count is not the important part on its own — which examples you pick is. Two properties decide whether examples help or mislead:

🔑 Relevance points the examples at your task; diversity spreads them across its range. You need both — relevant-but-narrow over-fits; diverse-but-off-topic teaches the wrong function.
SituationHow manyWhy
Simple, well-defined task3Enough to lock format + show a little range
Typical task3–5Anthropic's recommended sweet spot
Complex task, many categories/edge casesMore (scale up)Each category/edge case needs representation
Very few examples, all similar⚠️ riskyOver-fits to their surface form (see 3.5)
Let Claude help curate. You can ask Claude to evaluate your examples for relevance and diversity, or to generate additional examples based on your initial set — a fast way to broaden coverage before you finalize the prompt.
More is not automatically better. Each example costs input tokens on every call, and a redundant fourth example that repeats the first two adds cost without adding coverage. Add examples to fill gaps in range, not to pad the count.

DIAGRAM Picking a set that covers the range

flowchart TD A["Draft an example set"] --> R{"Each example relevant
to the real inputs?"} R -->|"no — off-domain / wrong format"| FIX1["🟠 Replace with
use-case-mirroring examples"] R -->|"yes"| D{"Set diverse enough?
edge cases + categories covered?"} D -->|"no — all similar"| FIX2["🟠 Add variety
ask Claude to generate more"] D -->|"yes, 3–5 (more if complex)"| GOOD["🟢 Ship the set"] FIX1 --> D FIX2 --> GOOD classDef ok fill:#d4edda,stroke:#28a745,color:#155724; classDef gate fill:#ffe8cc,stroke:#ff9f40,color:#9a4a0a; class GOOD ok; class FIX1 gate; class FIX2 gate;

CODE A relevant + diverse set, and asking Claude to extend it

Four examples that mirror the task (short product reviews → sentiment) while spanning categories and a tricky mixed case — that's diversity doing real work, not four near-duplicates.

# Relevant (all short product reviews) AND diverse (pos / neg / neutral / mixed)
system = "Label each review's sentiment: positive, negative, neutral, or mixed."
examples = """<examples>
<example><review>Battery lasts all day, love it.</review><label>positive</label></example>
<example><review>Screen cracked on day two.</review><label>negative</label></example>
<example><review>It's a phone. Does phone things.</review><label>neutral</label></example>
<example><review>Camera is stunning but it overheats badly.</review><label>mixed</label></example>
</examples>"""

# Let Claude broaden coverage before you finalize
audit = client.messages.create(
    model="claude-opus-4-8",
    max_tokens=16000,
    system=system,
    messages=[{"role": "user", "content":
        f"{examples}\n\nAre these examples relevant and diverse? "
        "Suggest 2 more that cover edge cases my set is missing."}],
)

TRADE-OFFS Too few vs. too many

✅ 3–5 relevant, diverse

  • Locks format and shows the range
  • Covers the common categories + a couple of edge cases
  • Modest, predictable token cost

⚠️ Too few / all similar / too many

  • Too few + narrow → over-fits their surface form (3.5)
  • Off-domain examples → teaches the wrong pattern
  • Many near-duplicates → pure token cost, no coverage gain
Optimize for coverage per example: fewer examples that each add a distinct category or edge case beat a long list of look-alikes.

EXAM TRAPS

Trap: "Always use exactly N examples." → Anthropic recommends 3–5 for best results and to scale up for complex tasks. It's a guideline tied to task complexity, not a fixed number.
Trap: "Relevance is enough." → Relevant-but-narrow examples over-fit. You also need diversity so Claude doesn't latch onto an incidental shared trait.
Trap: "Diversity means unrelated examples." → Diverse examples still must mirror your actual use case. Off-domain variety teaches the wrong function.
Trap: "I have to write all examples myself." → You can ask Claude to evaluate your set for relevance/diversity and to generate additional examples from your seeds.

PRACTICE

Q1 · How many examples does Anthropic recommend, and when do you add more?

3–5 for best results, scaling up for more complex tasks (more categories, more edge cases). The count follows task complexity — add examples to fill genuine gaps in coverage.

Q2 · Why isn't relevance alone sufficient?

If every relevant example shares an incidental trait (all short, all one category), Claude can pick up that unintended pattern and over-fit. Diversity — varying the examples and covering edge cases — prevents that while keeping them relevant.

Q3 · How can Claude itself help you choose examples?

You can ask Claude to evaluate your examples for relevance and diversity, and to generate additional examples based on your initial set — a quick way to broaden coverage and catch missing edge cases before finalizing the prompt.