Claude Certified Architect

Foundations · CCAR-F

Domain 4 — 20%

Task 4.2

Few-Shot Prompting

When and how to use examples effectively

📘What You Need to Know

What Few-Shot Prompting Does

Few-shot prompting provides 2–4 input/output examples before the actual task. Examples teach the model your expected format, classification boundaries, and reasoning style without lengthy instructions. They are especially powerful when the task has fuzzy boundaries or a custom output structure that standard instructions cannot capture.

Few-shot is not "more examples = better." Each example consumes context tokens and can introduce contradictions if formats differ. The exam tests whether you know when few-shot adds value and how many examples to include.

The Sweet Spot: 2–4 Examples

Research and exam guidance converge on 2–4 examples as optimal. Two examples establish the pattern. Three adds diversity across categories. Four can cover an edge case without bloating the prompt. Beyond six examples, accuracy gains flatten while token cost and format drift risk increase.

If you need more than six examples to get reliable output, the task likely needs a different approach — structured output with tool_use, a validation-retry loop, or explicit criteria instead of more demonstrations.

🔑Key Concept

2–4 examples is the exam sweet spot. More than 6 bloats the prompt without meaningful accuracy gains.

Format Consistency Across Examples

Every few-shot example must follow identical output structure. If example 1 returns JSON with fields {category, confidence, reason} and example 2 returns a prose paragraph, the model learns that either format is acceptable — and your production output becomes unpredictable.

Copy the exact template for each example. Same field names, same ordering, same delimiters, same level of detail in the reason field. Format consistency is non-negotiable.

# Consistent format (correct)
Example 1:
Input: "Great product, arrived broken though lol"
Output: {"sentiment": "mixed", "confidence": 0.85, "reason": "Positive product praise offset by damage complaint with sarcastic tone"}

Example 2:
Input: "Absolutely love it!"
Output: {"sentiment": "positive", "confidence": 0.95, "reason": "Unambiguous positive language with no qualifiers"}

# Inconsistent format (wrong)
Example 1: {"sentiment": "mixed", "confidence": 0.85}
Example 2: Sentiment: positive. The customer seems happy.

Edge Case Coverage and Diversity

At least one example should cover an ambiguous or edge case — sarcasm, mixed sentiment, partial data, or boundary classification. Without an edge case example, the model defaults to the "easy" pattern from your clear examples and mishandles real-world ambiguity.

Diversity means covering different categories, not repeating the same pattern with different words. Three positive-sentiment examples teach nothing a single positive example would not. One positive, one negative, and one mixed/sarcastic example teach the full decision space.

  • •Include at least one ambiguous or edge case example
  • •Cover different categories — not three variations of the same class
  • •Match example difficulty to expected production input distribution
  • •Keep input length realistic — toy examples do not transfer to real data

When Few-Shot Is and Is Not Worth It

Few-shot is most valuable for ambiguous classification (sentiment with sarcasm), custom output formats, domain-specific reasoning patterns, and fuzzy boundaries between categories. It is unnecessary for simple well-defined tasks, clear objective criteria, and standard output formats where tool_use schemas already enforce structure.

On the exam, if the task has a JSON schema and clear rules, adding 10 few-shot examples is wrong. If the task involves sarcasm detection with a custom reasoning format, 3 well-chosen examples is correct.

⚠️Watch out

Do not use few-shot to compensate for vague instructions. Examples teach format and boundaries; explicit criteria define what to flag.

⚠️Exam Traps

Trap: Using 10+ few-shot examples for maximum accuracy

Why it's wrong: Beyond 6 examples, prompt bloat increases without meaningful accuracy gains — and format drift risk rises.

Correct approach: Use 2–4 diverse examples with consistent format and at least one edge case.

Trap: Examples with inconsistent output formats

Why it's wrong: Mixed formats teach the model that any structure is acceptable — production output becomes unpredictable.

Correct approach: Every example uses identical field names, ordering, delimiters, and detail level.

Trap: All examples showing easy, unambiguous cases

Why it's wrong: Without edge case coverage, the model fails on sarcasm, mixed sentiment, and boundary inputs.

Correct approach: Include at least one ambiguous or edge case example alongside clear category examples.

Trap: Adding few-shot examples to tasks with clear criteria and tool_use schemas

Why it's wrong: Structured output already enforces format — extra examples waste tokens without adding value.

Correct approach: Reserve few-shot for ambiguous classification and custom formats; use schemas for structured extraction.

✓Concept Check

You are building a sarcasm-aware sentiment classifier with custom JSON output. How many few-shot examples should you include?

🔨Build Exercise

Intermediate35 minutes

Design Few-Shot Examples for Classification

What you'll learn

  • •Create effective few-shot example sets with 2–4 examples
  • •Enforce format consistency across all examples
  • •Include edge case coverage for ambiguous inputs