Rubric
Contents — domains, guide and mocks

Few-shot examples for consistency

CCAR-F 4.214 min read · checked 21 September 2026

Task statementApply few-shot prompting to improve output consistency and quality

Instructions alone versus instructions plus examples

Instruction only

Tag each product review with
its main topic and sentiment.
Return JSON.

Instruction + examples

Tag each review with its main
topic and sentiment. Return JSON.
<examples>
<example>
Review: "Arrived late but the
jacket is lovely."
{"topic":"product",
 "sentiment":"positive",
 "secondary":"delivery"}
Why: the complaint is minor;
the verdict is on the jacket.
</example>
<example>
Review: "ok"
{"topic":null,
 "sentiment":"neutral"}
</example>
</examples>
The instruction is identical. The examples fix the format, show how an empty field looks, and demonstrate the one judgement call the instruction left open.

What examples do that instructions cannot

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 examples improve both accuracy and consistency. Its consistency guide goes further: examples of the desired output are more effective than abstract instructions. The reason is simple. An instruction describes a pattern in words, and words leave room for interpretation — “main topic” can mean the first thing mentioned, the most-discussed thing, or the thing the star rating reflects. An example is the pattern itself. The model does not have to interpret it, only match it.

Examples are especially good at three things. They pin down format — exact field names, date style, how an empty value is written. They settle judgement calls — which way to go when a case could plausibly be labelled two ways. And they set tone and length, which are notoriously hard to describe in words. When the complaint is “the output is inconsistent from one run to the next”, one of those three is usually underspecified.

What makes an example set work

Weak example set

  • Five examples, all short, all positive
  • Every one has every field filled in
  • Invented toy inputs unlike real traffic
  • Answers only — no reason for the choice

Strong example set

  • 3–5 examples drawn from real inputs
  • Includes an ambiguous case and an empty one
  • Varied length, wording and layout
  • A one-line reason on the hard case
  • Wrapped in <example> tags
Anthropic’s guidance asks for examples that are relevant, diverse and clearly marked. The left set teaches the model a pattern you did not intend.

Choosing the examples

The documentation’s guidance is to include three to five examples, and to make them relevant (mirror your real use case), diverse (cover edge cases and vary enough that Claude does not pick up unintended patterns) and structured (wrap each in <example> tags, and the set in <examples>, so Claude can tell them apart from the instructions). Each of those words guards against a specific failure.

If your examples are…Claude may learn…Fix
All the same lengthThat every answer should be that lengthVary length deliberately
All positive, or all one categoryThat this category is the defaultCover each label, including the rare one
All completeTo fill every field — even by guessingInclude one where a field is honestly null
All easyNothing about the cases that actually go wrongSpend examples on the ambiguous boundary
Untagged, mixed into instructionsTo treat example text as instructions or as inputWrap them in <example> tags

The third row matters most in extraction work. If every example shows a value for every field, Claude learns that a complete record is what you want — and when a document genuinely lacks a field, it may invent a plausible one. One example with an explicit null teaches that “not stated” is an acceptable, even expected, answer. (Making the schema allow null is the other half; see 4.3.)

Spend your examples where the model is actually uncertain. You find those cases the same way you find false positives: run the prompt on a sample, collect the outputs that disagree with what a human would do, and turn the most common disagreement into an example. The docs also suggest asking Claude itself to evaluate an example set for relevance and diversity, or to propose more cases once you have a starting set.

Examples that show the reasoning, not just the answertext
<instructions>
Route each IT helpdesk message to one queue: access, hardware,
software, or security. Reply with the queue and a one-line reason.
</instructions>

<examples>
<example>
Message: My laptop won't turn on after the update last night.
Reason: the machine itself fails to boot; the update is context.
Queue: hardware
</example>
<example>
Message: I got an email asking me to "re-confirm my password" and
I clicked the link before I noticed the sender.
Reason: a possible credential leak outranks a password problem.
Queue: security
</example>
<example>
Message: Can't log in to the expenses tool, says account disabled.
Reason: the account state is the problem, not the tool.
Queue: access
</example>
</examples>

The second example is the one doing the work. “Password” would pull a naive router towards access; the reason line shows the priority rule — possible compromise beats inconvenience — so Claude can apply it to a case it has not seen, such as a lost phone with the authenticator app on it. The multishot guidance notes that examples work with extended thinking too: showing a short reasoning pattern inside the examples helps the model generalise the judgement rather than copy the surface wording.

Examples for tool calls

When Claude produces structured output by calling a tool, the JSON schema says what shape the input must have — but not how it is used. Anthropic’s engineering write-up on advanced tool use puts the gap this way: a schema cannot say which date format your API expects, whether an ID looks like a UUID or USR-12345, or when an optional nested object should be filled in. For that, a tool definition can carry an input_examples array.

A tool definition with input examplespython
create_ticket = {
    "name": "create_ticket",
    "description": "Open a support ticket. Use for faults the customer "
                   "cannot fix themselves; not for billing questions.",
    "input_schema": {
        "type": "object",
        "properties": {
            "title":    {"type": "string"},
            "priority": {"type": "string", "enum": ["low", "normal", "high"]},
            "due_date": {"type": "string", "description": "YYYY-MM-DD"},
            "reporter_id": {"type": "string"},
        },
        "required": ["title", "priority"],
    },
    # Each example must itself validate against input_schema (else HTTP 400).
    "input_examples": [
        {"title": "VPN drops every 10 minutes", "priority": "high",
         "due_date": "2026-09-23", "reporter_id": "USR-10442"},
        {"title": "Request second monitor", "priority": "low"},  # minimal
    ],
}

The documentation’s rules for these are worth knowing: every example must validate against the tool’s input_schema or the request fails with a 400 error; they work on your own client tools but not on server tools such as web search; and they cost prompt tokens — roughly tens of tokens for a simple example, a couple of hundred for a complex nested one. The engineering post recommends one to five examples per tool, realistic values rather than placeholders, a mix of minimal and full calls, and adding them only where correct usage is not obvious from the schema. Anthropic reports that in its internal testing, examples raised accuracy on complex parameter handling from 72% to 90%.

Which consistency lever fits the problem?

What is inconsistent?
  • Judgement on ambiguous cases
    Examples with reasonsin <examples> tags
  • Tool argument conventions
    input_exampleson the tool definition
  • JSON shape or field types
    Structured outputsschema enforcement — 4.3
  • A rule that must always hold
    Validate in codeand retry — 4.4

Traps the wrong answers are built from

Tempting but wrongDo this instead
Adding more instruction text when outputs keep varyingShow 3–5 examples of the exact output you want, including the hard cases.
Examples that are all similar, easy or happy-pathChoose examples from real failures: ambiguous, rare and empty cases.
Every example has every field filledInclude an example where a missing value is returned as null.
Showing only the answer on a judgement callAdd a short reason so the model can generalise the rule.
Mixing examples into instructions without markersWrap each in <example> tags inside an <examples> block.

You should now be able to

  • Recognise when inconsistent output calls for examples rather than more instructions.
  • Build a relevant, diverse set of 3–5 examples from observed failures.
  • Write examples that demonstrate reasoning on ambiguous cases, not just answers.
  • Use a null example to stop an extractor inventing missing values.
  • Add input_examples to a tool definition and state their constraints.

Practice questions

Original questions written for this lesson, in the exam’s style. Answer first, then open the reasoning — every option is explained, including why the wrong ones are tempting.

  1. Question 1

    An insurer’s claim classifier has a detailed system prompt defining each claim type. Reviewers find it consistently puts storm-damaged vehicles under “weather” one day and “motor” the next, depending on wording.

    What is the most effective next step?

    1. ARewrite the definitions of “weather” and “motor” at greater length.
    2. BAdd ten more examples of clear-cut motor claims.
    3. CTell the model to think very carefully about borderline claims.
    4. DAdd examples of storm-damaged vehicles, labelled and with a one-line reason.
    Show answer and reasoning
    1. AIncorrect. The definitions already exist; more words about them leave the same boundary open to interpretation.
    2. BIncorrect. Easy examples do not touch the ambiguous boundary where the inconsistency lives.
    3. CIncorrect. It does not say which way the borderline goes, so each run can still decide differently.
    4. DCorrect. Targeted examples on the ambiguous case show both the decision and the rule behind it, which is what makes it consistent.
  2. Question 2

    An extraction prompt pulls invoice fields from supplier PDFs. All four examples in the prompt show complete invoices. On invoices with no purchase-order number, the model sometimes returns a plausible-looking but invented PO number.

    Which change addresses the cause?

    1. AAdd an example invoice with no PO, extracted as po_number: null.
    2. BRemove all the examples so the model is no longer biased by them.
    3. CMake po_number a required string in the schema.
    4. DInstruct the model in capitals never to invent data.
    Show answer and reasoning
    1. ACorrect. The examples taught that a complete record is expected; an explicit null example shows that “not present” is a valid answer.
    2. BIncorrect. That discards the format and consistency the examples provide, and does not teach null handling.
    3. CIncorrect. Requiring a string pushes the model to produce one even when the document has none — the opposite of the fix.
    4. DIncorrect. An instruction helps less than showing the case, and emphasis alone does not demonstrate what to return.
  3. Question 3

    An internal IT agent calls a create_ticket tool. Calls are valid JSON, but dates arrive in three different formats and the optional reporter object is filled in with guessed values.

    Which two changes are most appropriate? (Select 2.)

    1. AAdd input_examples showing a full call and a minimal call with realistic values.
    2. BState the expected date format in the due_date property description.
    3. CAdd placeholder examples such as {"due_date": "string"}.
    4. DInclude examples that omit required fields to show flexibility.
    5. EForce tool_choice to create_ticket on every request.
    Show answer and reasoning
    1. ACorrect. Examples show conventions the schema cannot express, including when optional fields are left out.
    2. BCorrect. A precise field description removes the ambiguity that produced three formats.
    3. CIncorrect. Placeholder values teach nothing about real conventions; the guidance is to use realistic data.
    4. DIncorrect. Every input example must validate against the schema, or the request fails with a 400 error.
    5. EIncorrect. Forcing the tool addresses whether it is called, not how its arguments are formatted.

Sources

Drafted with AI assistance and checked against the sources above; expert review is in progress. Spotted an error? Tell us and it gets fixed, dated and listed on how this is written.