CertSafari
    Anthropic Claude Certified Architect – Professional (CCAR-P)· Lessons

    Domain 2 · Lesson 9/38

    Few-shot and chain-of-thought prompting for Claude

    Apply prompt engineering techniques

    17 min read
    2.6% of exam
    6 sources
    Published 19 Oct 2026
    Docs as of 14 Oct 2026

    What you will be able to do

    • Decide when a prompt needs zero, one or a few examples, and add them in that order
    • Write example sets that teach Claude the intended pattern instead of surface features
    • Prompt chain-of-thought in its basic, guided and structured forms
    • Choose between extended thinking and manual chain of thought for a given task
    • Lay out a prompt that combines long documents, instructions and a query

    Key concept

    Showing versus telling — Instructions tell Claude what you want. Examples show the output pattern, and chain-of-thought shows the reasoning path. You add each one only when telling alone has stopped producing consistent, correct results.

    1.Zero-shot, one-shot and few-shot prompting

    A zero-shot prompt is made of instructions alone, and for many tasks that is all you need. Claude follows clear, explicit direction well. A zero-shot prompt succeeds when it states the output format and constraints, and when it explains the reason behind each rule. A rule like "never use ellipses" works better with its reason attached: the text will be read aloud by a text-to-speech engine that cannot pronounce them. Given the reason, Claude can also handle cases the rule never mentioned, because it is able to generalise from the explanation.

    Some requirements are easier to show than to describe, and that is when examples start to pay off. Typical cases are a summary style, a tone of voice, or a labelling convention with fine distinctions. Another is a set of instructions that keeps producing outputs that differ slightly from run to run. Putting example inputs with their outputs in the prompt is called one-shot prompting when there is one example and few-shot (or multishot) prompting when there are several. A few well-crafted examples improve both accuracy and consistency.

    When each level of prompting is the right choice
    ApproachWhat the prompt containsUse it when
    Zero-shotExplicit instructions, format, constraints and the reasons for themThe output can be fully described in words
    One-shotInstructions plus one example of the desired outputThe format, tone or style is easier to show than describe
    Few-shotInstructions plus several varied examplesOne example still leaves outputs inconsistent, or the task has subtle patterns and edge cases

    Escalate one step at a time. Start with one example, and add more only if the output still doesn't match. Each example adds length, and as the next section explains, every detail in an example becomes something Claude may copy. Examples also extend beyond text. In one vision walkthrough, Claude misread a speedometer in km/h until example images were added to the prompt. Few-shot prompting with images doesn't always work, though, so test it on your own case.

    Few-shot examples are the standard fix when outputs drift in format or label spelling across similar inputs, such as a triage prompt that returns "High" on one ticket and "high priority" on the next. Asking Claude to explain its reasoning in prose does not fix this, because the problem is the output's shape, not its reasoning. Adding one untagged example after the instructions is the weakest version of the fix. A single example shows no variety, and without tags Claude cannot reliably tell the demonstration apart from the instructions. Several varied ticket-and-output pairs, each wrapped in example tags, teach the exact labels and layout you expect.

    Checkpoint 1 of 8· Check yourself

    A zero-shot triage prompt gives the correct priority, but the label varies between tickets: "High" on one and "high priority" on the next. What is the most effective fix?

    Checkpoint 2 of 8· Exam question

    A team's support-ticket triage prompt asks Claude to output a category label and priority score, but real outputs vary in formatting and label spelling across similar tickets. The team has not yet included any example outputs in the prompt. Which change is most likely to make outputs consistent?

    Sources123

    2.Crafting examples Claude learns the right lesson from

    Claude learns everything an example shows, including what you did not mean to teach. Modern Claude models pay very close attention to details in examples. A shared length, sentence structure or sentiment across your examples will be read as part of the pattern. Example sets should meet three requirements:

    • Relevant: they mirror your real use case closely, with the same kind of input and the same output shape.
    • Diverse: they cover edge cases and vary enough that Claude does not pick up unintended patterns.
    • Structured: each one is wrapped in example tags, and the set in examples tags, so Claude can tell demonstrations apart from instructions.

    A homogeneous example set fails in a specific way. It works on inputs that look like the examples and breaks on everything else. Adding more examples of the same kind makes the unwanted pattern stronger, so the count is not the fix. The fix is coverage: include each label, the hard boundary cases, and varied lengths and phrasings. Varied examples are most useful for nuanced or ambiguous cases, where the line between categories is hard to state in a written description alone.

    Moderation examples that cover both labels and very different kinds of content, from praise to threats to misinformationtext
    Comment: This movie was great, I really enjoyed it. The main actor really killed it!
    Classification: ALLOW
    
    Comment: Delete this post now or you better hide. I am coming after you and your family.
    Classification: BLOCK
    
    Comment: Stay away from the 5G cellphones!! They are using 5G to control you.
    Classification: BLOCK
    
    Comment: Thanks for the helpful information!
    Classification: ALLOW

    Tags matter as much as content. If an example sits loose among the instructions, Claude may treat its specific values as requirements, or treat an instruction as sample data. Wrapping each example in its own tag removes that ambiguity. Using the same tag names in every prompt keeps the structure predictable. Examples are also the easiest place to tune behaviour: changing the examples in a moderation prompt changes what it allows and blocks, with no other edits.

    Checkpoint 3 of 8· Check yourself

    Your team's moderation prompt has four varied, relevant comment-and-label pairs, but they are pasted in among the rules with no tags around them. What risk does this layout create?

    Checkpoint 4 of 8· Exam question

    While reviewing a few-shot prompt for a sentiment classifier, an engineer notices that all five included examples are short, positive-sentiment product reviews written in the same sentence structure. Model outputs on negative or mixed reviews are now unreliable. What is the most likely cause and fix?

    Sources124

    3.Chain-of-thought prompting in three forms

    Chain-of-thought (CoT) prompting asks Claude to reason step by step before giving its answer. It helps because a model answering in a single pass has no room for scratch work, checking or changing course. When Claude reasons first, it restates the problem, tries approaches and checks intermediate results. This matters most for tasks whose answer depends on intermediate work that would otherwise be squeezed into the response or skipped: multi-step analysis, maths, and decisions that weigh several factors.

    The three common ways to prompt chain-of-thought
    FormWhat you add to the promptWhat it gives you
    BasicA phrase such as "Think step-by-step"Reasoning before the answer, but Claude chooses what to reason about
    GuidedNamed reasoning stages in order: first consider X, then Y, then write the outputEnsures that the specific factors you care about are considered
    StructuredGuided stages, plus tags that separate reasoning (<thinking>) from the answer (<email>)Reasoning your code can strip out, and an answer it can extract cleanly
    Basic chain-of-thought: one closing sentence asks for reasoning before the emailtext
    Draft personalized emails to donors asking for contributions to this year's Care for Kids program.
    
    Program information:
    <program>
    {{PROGRAM_DETAILS}}
    </program>
    
    Donor information:
    <donor>
    {{DONOR_DETAILS}}
    </donor>
    
    Think step-by-step before you write the email.

    Each form gives you more control than the one before. The basic form lets Claude decide what is worth thinking about. The guided form names the stages, for example the donor's giving history first, then the parts of the programme that fit them, then the email. Use it when the reasoning has to cover specific ground. The structured form adds output tags, which production pipelines usually need. A moderation filter can ask for its reasoning in thinking tags and its verdict in output tags, then parse only the verdict. In a vision example, the same thinking-then-answer layout fixed a dog count Claude had first got wrong.

    Checkpoint 5 of 8· Match them up

    Match each form of chain-of-thought prompting to what you add and what it gives you

    Tap a term, then the definition that fits it.

    Sources524

    4.Extended thinking versus manual chain of thought

    Extended thinking is built-in chain-of-thought. When it is active, Claude reasons in thinking content blocks that arrive before its text response. On models that support it, extended thinking is generally preferable to writing CoT instructions by hand. How you turn it on depends on the model. On Claude Opus 4.6 to 4.8 and Claude Sonnet 4.6, thinking stays off until you set adaptive thinking, which lets Claude decide when and how deeply to think. Claude Sonnet 5 has it on by default.

    Turning on adaptive thinking, with the summarised thinking returned and max_tokens raised to leave room for itpython
    response = client.messages.create(
        model="claude-opus-5-5",
        max_tokens=16000,
        thinking={"type": "adaptive", "display": "summarized"},
        messages=[
            {
                "role": "user",
                "content": "What is the greatest common divisor of 1071 and 462?",
            }
        ],
    )

    Manual CoT is still the right choice in two cases. The first is when extended thinking isn't available, such as on the free Claude.ai plan. The second is when you need reasoning you can review. A thinking block never contains the raw chain of thought. With display set to summarized it holds a summary of Claude's reasoning. With omitted, the default on many models, its thinking field comes back empty. Reasoning written in thinking tags as part of the response is exactly what Claude wrote, so an auditor can read it in full. The two approaches can also be combined: even with extended thinking on, explicit CoT instructions can still help on complex tasks.

    Thinking has costs, so it should not be on for every request. Thinking tokens are billed as output tokens even when the text is not returned, and they count toward max_tokens. They also add latency. You can steer thinking turn by turn. Adding "Please think hard before responding." to a user message encourages it, and "Answer directly without deliberating." discourages it. An agent harness can add the first phrase on planning steps and the second on routine confirmations. Steering phrases change model behaviour, so measure how often thinking triggers, token use, latency and answer quality before you ship them.

    Checkpoint 6 of 8· Fill the gap

    You want this adaptive-thinking request to return Claude's thinking text in its thinking blocks, not an empty thinking field. Which display value goes in the blank?

    response = client.messages.create(
        model="claude-opus-5-5",
        max_tokens=16000,
        thinking={"type": "adaptive", "display": " ? "},
        messages=[
            {
                "role": "user",
                "content": "What is the greatest common divisor of 1071 and 462?",
            }
        ],
    )

    Sources256

    5.Placing long documents, examples and the query

    Prompts that combine large documents with instructions and examples need a deliberate layout. Inputs of 20k+ tokens are where layout matters most; managing the limits themselves is covered under context window budgeting. Three practices apply:

    • Put the long documents near the top, above the query, instructions and examples. This improves performance on all models, so moving the question to the very top is the wrong direction.
    • Wrap each document in document tags with source and document_content subtags, and nest them all inside a documents tag. Keep this structure rather than pasting raw text, because the tags let Claude tell the documents apart.
    • Ask Claude to quote the relevant passages, in their own tag, before it does the task. This keeps it focused on the content that matters and ignoring the rest.

    Quoting first is the long-document version of chain-of-thought: the extracted quotes become the intermediate work the answer builds on. If answers keep missing details buried mid-document, quote grounding plus a documents-first layout is the fix. Cutting the input down to a single document is not, because the multi-document tag structure exists precisely so Claude can work across several sources in one prompt.

    Checkpoint 7 of 8· Check yourself

    An analyst's prompt combines about 60k tokens of supplier contracts with instructions, two tagged examples and the question "Which contracts allow termination without notice?" Answers keep missing clauses buried in the middle of the contracts. Which change follows the recommended layout?

    Checkpoint 8 of 8· Exam question

    An engineer is building a Claude prompt that analyzes several long internal documents and answers a question about them. Responses sometimes ignore details buried in the middle of the documents. Which of the following changes are consistent with documented long-context prompting guidance? (Select all that apply.)(Select 3)

    0 of 3 selected

    Sources1

    Sources

    (6)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Be specific about the desired output format and constraints.”
      ↩︎ Zero-shot, one-shot and few-shot prompting
      “Claude is smart enough to generalize from the explanation.”
      ↩︎ Zero-shot, one-shot and few-shot prompting
      “A few well-crafted examples (known as few-shot or multishot prompting) improve accuracy and consistency.”
      ↩︎ Zero-shot, one-shot and few-shot prompting
      “Relevant: Mirror your actual use case closely.”
      ↩︎ Crafting examples Claude learns the right lesson from
      “Wrap examples in <example> tags (multiple examples in <examples> tags) so Claude can distinguish them from instructions.”
      ↩︎ Crafting examples Claude learns the right lesson from
      “Use consistent, descriptive tag names across your prompts.”
      ↩︎ Crafting examples Claude learns the right lesson from
      “Place your long documents and inputs near the top of your prompt, above your query, instructions, and examples.”
      ↩︎ Placing long documents, examples and the query
      “wrap each document in <document> tags with <document_content> and <source> (and other metadata) subtags for clarity”
      ↩︎ Placing long documents, examples and the query
      “ask Claude to quote relevant parts of the documents first before carrying out its task”
      ↩︎ Placing long documents, examples and the query
      “This helps Claude focus on the relevant content and ignore the rest of the document.”
      ↩︎ Placing long documents, examples and the query
      “Examples are one of the most reliable ways to steer Claude's output format, tone, and structure.”
      ↩︎ Key concept
      “Diverse: Cover edge cases and vary enough that Claude doesn't pick up unintended patterns.”
      ↩︎ Exam trap 1
      “Place your long documents and inputs near the top of your prompt, above your query, instructions, and examples.”
      ↩︎ Exam trap 3
      “A few well-crafted examples (known as few-shot or multishot prompting) improve accuracy and consistency.”
      ↩︎ Exam trap 4
      “Examples are one of the most reliable ways to steer Claude's output format, tone, and structure.”
      ↩︎ Checkpoint
      “Diverse: Cover edge cases and vary enough that Claude doesn't pick up unintended patterns.”
      ↩︎ Prediction
      “Structured: Wrap examples in <example> tags (multiple examples in <examples> tags) so Claude can distinguish them from instructions.”
      ↩︎ Checkpoint
      “Place your long documents and inputs near the top of your prompt, above your query, instructions, and examples. This improves performance across all models.”
      ↩︎ Checkpoint
    2. 2.
      “Start with one example (one-shot). Only add more examples (few-shot) if the output still doesn't match your needs.”
      ↩︎ Zero-shot, one-shot and few-shot prompting
      “Examples aren't always necessary, but they shine when explaining concepts or demonstrating specific formats.”
      ↩︎ Zero-shot, one-shot and few-shot prompting
      “Claude 4.x and similar advanced models pay very close attention to details in examples.”
      ↩︎ Crafting examples Claude learns the right lesson from
      “Use tags to separate reasoning from the final answer.”
      ↩︎ Chain-of-thought prompting in three forms
      “Structure your prompt to provide specific reasoning stages.”
      ↩︎ Chain-of-thought prompting in three forms
      “When available, extended thinking is generally preferable to manual chain of thought prompting.”
      ↩︎ Extended thinking versus manual chain of thought
      “Extended thinking isn't available (i.e. the free Claude.ai plan)”
      ↩︎ Extended thinking versus manual chain of thought
      “The two approaches are complementary, not mutually exclusive.”
      ↩︎ Extended thinking versus manual chain of thought
    3. 3.
      “Note though that few-shot prompting with images doesn't always work but it is worth trying on your use case.”
      ↩︎ Zero-shot, one-shot and few-shot prompting
    4. 4.
      “especially helpful for nuanced or ambiguous cases where the category boundaries may not be entirely clear”
      ↩︎ Crafting examples Claude learns the right lesson from
      “explicitly instruct Claude to break down its process into clear steps inside <thinking> tags”
      ↩︎ Chain-of-thought prompting in three forms
    5. 5.
      “Claude works through the problem in its own words before answering”
      ↩︎ Chain-of-thought prompting in three forms
      “where the quality of the answer depends on intermediate work that would otherwise be compressed into the response itself or skipped”
      ↩︎ Chain-of-thought prompting in three forms
      “what you see is never the raw chain of thought: the text in a thinking block is a summary of Claude's reasoning”
      ↩︎ Extended thinking versus manual chain of thought
      “the tokens Claude spends reasoning are billed as output tokens, even when the thinking text isn't returned to you”
      ↩︎ Extended thinking versus manual chain of thought
      “which lets Claude determine when and how deeply to think based on the request”
      ↩︎ Extended thinking versus manual chain of thought
      “what you see is never the raw chain of thought: the text in a thinking block is a summary of Claude's reasoning”
      ↩︎ Exam trap 2
    6. 6.
      “Per-message steering is useful when only some requests in a conversation warrant extended reasoning.”
      ↩︎ Extended thinking versus manual chain of thought
      “Prompt-based steering changes model behavior, so treat it like any other prompt change: measure before you ship.”
      ↩︎ Extended thinking versus manual chain of thought

    Ready to test yourself?

    Practise the 12 questions on this subdomain.

    Spotted a mistake, or was something unclear? Tell us.