Study guides / CCAR-P / Domain 6

Claude Models, Prompting & Context Engineering · Lesson 3 of 5

6.3 - Prompting Techniques: Zero-Shot, Few-Shot and Chain-of-Thought

Choose between zero-shot, few-shot and reasoning-based prompting for a given failure mode, and validate the choice on an eval set instead of intuition.

Prompting techniques are remedies for specific failure modes, not a ladder to climb. Anthropic’s prompt-engineering guide starts with three prerequisites: defined success criteria, a way to test against them empirically, and a first-draft prompt. It also notes that not every failing eval is best solved by prompting; sometimes selecting a different model improves cost and latency more easily, and tuning effort is a related lever (see 6.1). So the professional sequence is diagnose the failure, apply the smallest technique that addresses it, and measure (see 3.4 for diagnosis).

Zero-shot: the default, and where it stops being enough

Zero-shot means clear, direct instructions with the context and motivation behind them and no examples. Anthropic frames Claude as a capable new employee who lacks your norms: the more precisely you explain the task, format and reasons, the better the result. If a zero-shot prompt is correct and consistent on your eval set, stop; every added example or reasoning step costs tokens on every call.

Zero-shot stops being enough in recognisable ways: format drifts between runs, judgement on ambiguous cases is inconsistent, or extraction returns empty fields for information that is present but arranged differently from what the instructions imagined. More instructions rarely fix these; a demonstration usually does.

Few-shot (multishot): teach the pattern

Anthropic describes examples as one of the most reliable ways to steer output format, tone and structure. Its guidance for building them: make them relevant (mirroring the real use case), diverse (covering edge cases and varied enough that the model does not latch onto unintended patterns) and structured (wrapped in <example> tags, several inside <examples>, so they are not confused with instructions). The docs suggest 3 to 5 examples; do not memorise a number, because coverage of your failing scenarios matters more and your eval decides when more examples stop helping.

Two practices raise the value of each example. Include the reasoning for the choice (why this label or field value rather than a plausible alternative) so the model learns the principle instead of the surface pattern. And include negative and null cases, such as an input where a field is genuinely absent and the correct output is null, which also reduces fabricated values.

<examples>
<example>
<input>Please refund order 8891, it arrived broken.</input>
<reasoning>A specific order number plus a defect means an order-level
action, so the order tool is right, not the account tool.</reasoning>
<output>lookup_order</output>
</example>
</examples>

Examples carry risks: they can over-anchor the model on their length, wording or label mix, they cost input tokens on every call (a stable block is a good caching candidate, see 6.5), and they go stale when policy changes. Evaluate on held-out cases, never on the examples in the prompt.

A practical mapping from symptom to first remedy:

SymptomFirst remedy
Inconsistent format or toneFew-shot examples, or a schema if the format is machine-read
Invalid or non-conforming JSONStructured outputs (output_config.format, strict tool use)
Fabricated values for absent fieldsNullable or optional fields plus an example that returns null
Inconsistent judgement on ambiguous casesExplicit criteria plus examples with reasoning
Multi-step reasoning errorsThinking and effort, or reasoning-style examples
Wrong tool chosenBetter tool descriptions first (see 1.1), then examples
Fields that should sum or reconcile do notValidation and retry in code

Key concept: match the technique to the failure mode

Instructions define intent, examples teach a pattern, schemas constrain format, thinking improves multi-step reasoning, and code validates invariants. Reaching for the wrong one is the classic mistake: “think step by step” does not fix an inconsistent output format, and few-shot examples do not guarantee valid JSON.

Chain-of-thought is now thinking plus effort

Classic chain-of-thought asked the model to reason in its visible answer. On current models the primary mechanism is thinking: when active, Claude reasons in thinking blocks before answering, which helps on maths, coding, analysis and long agentic work. Thinking tokens are billed as output tokens and count toward max_tokens, so it is a cost and latency decision. On Claude 4.6 and later models thinking is adaptive: the model decides when and how much to think, steered by the effort parameter and query difficulty. Defaults differ by model (see 6.1): on Opus 5 and Sonnet 5 it is on when you omit the parameter, on Fable 5.1 it is always on, and Haiku 4.5 uses the older manual mode. On Claude 4.7 and later models, setting budget_tokens returns a 400 error, so control depth with effort, and use max_tokens as the hard ceiling.

Anthropic’s prompting guidance for reasoning is short:

Reasoning is not free and often unnecessary. For simple classification, extraction or formatting, extra thinking adds latency and cost with no gain; lower effort, or tell the model to respond directly when a question needs no reasoning. On Opus 5, Sonnet 5 and Fable models thinking text is omitted from responses by default, so if a product needs a visible rationale, request it in the output contract.

Structured output and measurement

Make the output contract explicit. Structured outputs guarantee schema-compliant JSON via constrained decoding (with documented limits: no recursive schemas, no numeric or string-length constraints, and refusals or truncation can still occur); they do not guarantee correct values. Because prefill on the last assistant turn is unsupported on Claude 4.6 and later models, use instructions or structured outputs to force a format.

Then run an ablation on a held-out eval set: zero-shot baseline, then add criteria, then examples, then thinking or higher effort, changing one thing at a time. Track pass rate by category, input and output tokens and latency. Examples add input tokens per call; thinking adds output tokens; so compare techniques by cost per passing case, not by accuracy alone (see 3.2 for eval design and 3.5 for cost optimisation). Anthropic’s eval guidance favours automated grading and, for LLM grading, a different model as grader than the one that generated the output.

Common exam distractor

When output format or judgement is inconsistent, “add more detailed instructions” and “turn on maximum reasoning” are the tempting wrong answers; diverse examples with reasoning (or a schema for machine-read format) is the fix. The mirror-image distractor is the belief that examples or structured outputs make the content correct: they fix pattern and format, not facts.

Exam traps

Practice question

An invoice-extraction pipeline with detailed field instructions extracts correctly from tables but returns null for fields that appear in narrative paragraphs. Output is already schema-valid JSON. What is the best next step?

  • A Raise effort to the maximum level so the model reasons harder about the narrative sections of each document, and keep the rest of the prompt and the schema unchanged.

    The failure is structural variety, not shallow reasoning. Higher effort adds output tokens on every call and does not reliably teach the model what correct narrative extraction looks like.

  • B Add a preprocessing step that rewrites every narrative paragraph into a table before the model sees it, so all documents reach the extractor in the one format it already handles well.

    This adds infrastructure that must itself be maintained and can lose information. The model can handle varied structure when shown examples, which is a much cheaper first step.

  • C Make every field required and non-nullable in the schema so the model must always fill it, then reject any response that contains an empty value.

    Forcing required values on fields that are genuinely absent pushes the model to fabricate. Absent fields should be nullable with an example that returns null.

  • D Add a few diverse examples, including narrative documents and one absent-field case, with brief reasoning, then compare accuracy by document type on held-out documents. Correct

    Examples target the exact failing structure, the null case protects against fabrication, reasoning teaches the principle, and a held-out per-type comparison shows whether the change worked.

Build exercise: Run an ablation: zero-shot, few-shot and thinking on an extraction task

Intermediate · 75 minutes

You'll practice:

  1. Create 30 short documents with known field values: 10 tables, 10 narrative paragraphs and 10 mixed formats, including at least 5 where one field is genuinely absent. Set aside 6 as an example pool and keep 24 as a held-out eval set.

    Held-out data is what makes the comparison honest. Covering structures and absent fields lets you see which failure each technique fixes.

    You should see: A file with document text, expected fields (with null where absent), a structure label and a pool or held-out flag.

    Hints
    1. What structural differences between documents are most likely to change extraction behaviour?
    2. Stratify the split so each structure appears in both the pool and the held-out set, and never let an example-pool document appear in the eval.
    3. {'id': 7, 'structure': 'narrative', 'text': 'We ordered fifty units at ten pounds each on 3 March 2025.', 'expected': {'vendor_name': None, 'document_date': '2025-03-03', 'total_amount': 500.0}, 'split': 'heldout'}
  2. Run a zero-shot baseline with a schema-constrained output (nullable fields) on the held-out set. Record field-level accuracy by structure, input tokens and output tokens.

    The baseline shows where zero-shot fails (typically narrative and mixed documents) and gives you the token cost that any technique must be judged against.

    You should see: Per-structure accuracy with a visible gap between tables and narrative, and a mean token count per call.

    Hints
    1. Which fields need to allow null in the schema, and how will your grader distinguish a correct null from a missed value?
    2. Use anyOf with a string type and a null type for optional fields, additionalProperties false on the object, and compare field by field against the expected values.
    3. schema = {'type': 'object', 'properties': {'vendor_name': {'anyOf': [{'type': 'string'}, {'type': 'null'}]}, 'document_date': {'anyOf': [{'type': 'string'}, {'type': 'null'}]}, 'total_amount': {'anyOf': [{'type': 'number'}, {'type': 'null'}]}}, 'required': ['vendor_name', 'document_date', 'total_amount'], 'additionalProperties': False}
      r = client.messages.create(model='claude-sonnet-5', max_tokens=2000, system=SYSTEM,
          messages=[{'role': 'user', 'content': '<document>' + doc + '</document>'}],
          output_config={'format': {'type': 'json_schema', 'schema': schema}})
  3. Add 3 to 5 examples from the pool, wrapped in examples and example tags, each with input, brief reasoning and output. Cover a table, a narrative paragraph, a mixed document and one absent-field case. Re-run on the held-out set.

    This applies the relevant, diverse and structured guidance and tests whether demonstrations fix the specific structural failures, including fabrication.

    You should see: Higher accuracy on the previously weak structures, a null returned (not a guess) for absent fields, and a higher input token count per call.

    Hints
    1. Which two or three failure patterns from the baseline must the examples demonstrate, and what would an example that teaches the wrong pattern look like?
    2. Take examples only from the pool, vary structure and label distribution, and keep the reasoning to one or two sentences that state the principle.
    3. EXAMPLES = '<examples>\n<example>\n<document>Ordered 50 units at 10 pounds each on 3 March 2025.</document>\n<reasoning>Date written in words: convert to ISO 8601. Total is 50 x 10. No vendor is named, so vendor_name is null instead of a guess.</reasoning>\n<output>{"vendor_name": null, "document_date": "2025-03-03", "total_amount": 500.0}</output>\n</example>\n</examples>'
      SYSTEM = BASE_INSTRUCTIONS + '\n' + EXAMPLES
  4. Test a reasoning variant: repeat the few-shot run at low and high effort (or with thinking on versus prompted to respond directly). Compute cost per correct field for every variant using current pricing, and repeat each variant three times.

    Reasoning may or may not help this task. Measuring it against cost per correct field shows whether the extra output tokens buy anything and how noisy the result is.

    You should see: A comparison table where higher effort adds tokens and latency for little or no accuracy gain on this task, or a clear gain on a specific structure that justifies it.

    Hints
    1. If accuracy is flat between low and high effort, what does that say about which technique addressed the failure?
    2. Hold the prompt and cases constant and vary only effort; repeat runs and report the mean and spread rather than one number.
    3. for effort in ['low', 'high']:
          scores = []
          for trial in range(3):
              scores.append(run_eval(model='claude-sonnet-5', effort=effort))
          print(effort, sum(scores) / len(scores), max(scores) - min(scores))
  5. Write a short conclusion: the smallest technique that met your target, the evidence by structure, what still fails, and which remaining failures need a different remedy (a schema change or a validation rule) rather than more prompting.

    Choosing the smallest sufficient technique, and naming what prompting cannot fix, is the judgement the exam is looking for.

    You should see: A decision table that maps each residual failure to its remedy, plus a note on how you will detect drift when documents or the model change.

    Hints
    1. Which failures improved with examples, and which would you fix with code or schema instead?
    2. For each remaining failure decide whether it is a pattern problem (examples), a format problem (schema), a reasoning problem (thinking or effort) or an invariant problem (validation).
    3. Residual: total_amount does not equal the sum of line items -> validation rule + one retry with the discrepancy in the message; date in unusual locale format -> add one more diverse example; refusal on sensitive content -> handle stop_reason explicitly.

Sources