Your first 10 patterns
Few-Shot: Show, Don't Just Tell
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:
- The model picked the right category —
technical, because broken export functionality is closer to the "I can't log in" example than to a billing or sales question. - The output format matches the examples exactly. No capital letters, no period, no preamble. The examples set the format and the model copied it.
- 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
Zero-shot
- Fast to write
- Fine for common tasks
- Low context cost
Few-shot
- 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 case | Why it works |
|---|---|
| Classification with custom categories | Examples 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 handling | One 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:
- Diverse. Don't show three "I want a refund" billing examples; show billing, technical, and sales.
- Realistic. Use real(ish) inputs from your actual data, not toy phrases.
- Consistent in format. Whatever shape you used in example 1, use exactly the same shape in 2 and 3.
- 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. :::
Sign in to rate