Lesson 12 of 42

Your first 10 patterns

Few-Shot: Show, Don't Just Tell

4 min read

Few-shot prompting means giving the model 2 to 5 worked examples right inside the prompt. You're not describing the pattern — you're letting the model induce the pattern from your examples. It's the single most reliable upgrade when zero-shot wobbles.

A side-by-side comparison

Same classification task as the last lesson, but now with examples. The model is shown three labelled emails, then asked to classify a fourth.

Classify each customer email as one of: billing, technical, sales, other.
Reply with only the category.

Examples:
Email: "I cannot log in, the password reset never arrives." -> technical
Email: "Do you offer a yearly plan with a discount?" -> sales
Email: "I was charged twice this month." -> billing

Now classify:
Email: "The export to CSV is missing the last 3 columns." -> 

Captured output:

technical

Captured from Claude Sonnet 4.5 (claude-sonnet-4-5) on 2026-04-27. Re-runs may differ slightly.

Notice three things:

  1. The model picked the right categorytechnical, because broken export functionality is closer to the "I can't log in" example than to a billing or sales question.
  2. The output format matches the examples exactly. No capital letters, no period, no preamble. The examples set the format and the model copied it.
  3. No verbose explanation. The arrow notation (->) tells the model "give me the right side of the arrow", which it does.

Zero-shot vs few-shot — same task

0 examples

Zero-shot

Setup timeSeconds
Format consistencyWobbles on edge cases
Edge casesModel guesses
Pros
  • Fast to write
  • Fine for common tasks
  • Low context cost
2-5 examples

Few-shot

Setup time1-2 minutes per pattern
Format consistencyLocked by examples
Edge casesDemonstrated explicitly
Pros
  • Output format mechanically copied
  • Custom categories learned in context
  • Edge cases handled by demonstration

Why few-shot works

The model is, fundamentally, a next-token predictor. When you show it three examples that all look like Email: "..." -> category, the next thing it sees is Email: "..." -> — and the most likely continuation is one of the categories. The pattern is enforced by the shape of what came before.

This is why few-shot is so powerful for:

Use caseWhy it works
Classification with custom categoriesExamples teach what each label means in your context.
Specific output format (JSON, CSV, custom)Examples lock the format mechanically.
Style imitation (write like X)A few sentences of X's writing teach the voice better than ten adjectives.
Edge-case handlingOne example of the tricky case shows the rule in action.

How many examples to give

The "few" in few-shot usually means 2 to 5. Past that you hit diminishing returns and waste context window. Two simple rules of thumb:

  • Use 2 examples if the categories are obvious and you mostly want to lock format.
  • Use 3 to 5 examples if there are ambiguous edge cases or if the categories are hand-defined.

What makes a good example

Good few-shot examples are:

  1. Diverse. Don't show three "I want a refund" billing examples; show billing, technical, and sales.
  2. Realistic. Use real(ish) inputs from your actual data, not toy phrases.
  3. Consistent in format. Whatever shape you used in example 1, use exactly the same shape in 2 and 3.
  4. Bounded. Keep them short. Long examples burn context window and dilute the pattern.

The trap to avoid

If your examples are biased — e.g. all three examples are "billing" — the model will lean toward billing on the test input even when it shouldn't. The examples are training the model in real time. Curate them like you'd curate training data.

Next: persona — how a single line in the role slot reshapes vocabulary, hedging, and structure. :::

Quiz

Module 3: Your First Patterns

Take Quiz
Was this lesson helpful?

Sign in to rate

FREE WEEKLY NEWSLETTER

Stay on the Nerd Track

One email per week — courses, deep dives, tools, and AI experiments.

No spam. Unsubscribe anytime.