Appearance
Zero-Shot vs Few-Shot Prompting
Zero-shot means no examples. Few-shot means 2-5 examples. The difference is not just a number, it's a fundamental tradeoff between flexibility and control. Examples guide the model toward a specific format and reasoning style, but they also constrain it. This lesson covers when to use each, how to select examples, and when examples hurt more than they help.

What you'll learn
- Zero-shot: no examples, relies on the model's general knowledge. Fast, flexible, but less controlled
- Few-shot: 2-5 examples in the prompt. Better format control, but examples can bias the model
- Example selection matters more than example count, one well-chosen example beats three generic ones
The problem
You want the model to classify customer messages as "urgent" or "not urgent." Zero-shot: "Classify this message." The model's answer depends entirely on its training data's concept of "urgent." Few-shot: you provide two examples of what you consider urgent. Now the model matches your definition, not the generic one.
Options & when to use each
| Technique | Examples | Good for | Watch out for |
|---|---|---|---|
| Zero-shot | 0 | Simple tasks, broad outputs, when flexibility is the goal | Less control over format and style |
| One-shot | 1 | Establishing a format, simple classification | Single example can overfit the model's output |
| Few-shot | 2-5 | Complex tasks, specific formats, consistent reasoning | Examples can bias the model toward their specific patterns |
| Many-shot | 10+ | Very specific output formats, when the model needs to learn a pattern | Uses a lot of context window, diminishing returns after 5-8 examples |
Build it
Zero-shot
A zero-shot prompt relies entirely on the model's pre-training to interpret the instructions without examples.
python
prompt = "Classify the sentiment of this review as POSITIVE, NEGATIVE, or NEUTRAL.\n\nReview: {review}\n\nSentiment:"Few-shot
Providing a few well-chosen examples steers the model toward your specific output format and reasoning style.
python
prompt = """Classify the sentiment of product reviews.
Examples:
Review: "This product is amazing, I love it!"
Sentiment: POSITIVE
Review: "Broke after two days. Waste of money."
Sentiment: NEGATIVE
Review: "It works but the setup was confusing."
Sentiment: NEUTRAL
Now classify:
Review: "{review}"
Sentiment:"""Example selection rules
Carefully curate examples to ensure they represent the expected input distribution without biasing the model.
python
# Good examples are:
# 1. Representative, cover the range of inputs you expect
# 2. Balanced, equal number per category
# 3. Simple, don't use edge cases as examples
# 4. Recent, if the domain changes, update examples
BAD_EXAMPLES = [
# Edge case: too rare to be representative
("Review in Klingon: 'Qapla'!", "NEUTRAL"),
# Ambiguous: could be either
("It's fine.", "NEUTRAL? POSITIVE?"),
]What goes wrong
| Mistake | How you notice it | The fix |
|---|---|---|
| Examples bias the model | Model classifies everything as the majority example's category | Balance examples across categories. If you have 3 POSITIVE and 1 NEGATIVE example, the model skews POSITIVE |
| Examples are too specific | Model only matches the exact pattern from examples, fails on variations | Use diverse examples that cover different phrasings, not just one template |
| Examples contradict the instructions | Instructions say "be concise" but examples are verbose | The model follows examples more strongly than abstract instructions. Make examples match instructions |
| Too many examples | Context window fills up, diminishing returns | Start with 2 examples. Add more only if accuracy improves measurably |
Confirm it worked
Measure the impact of your examples by comparing the few-shot accuracy against a zero-shot baseline.
python
# Compare zero-shot vs few-shot accuracy
reviews = [("Love it!", "POSITIVE"), ("Terrible.", "NEGATIVE"), ("It's okay.", "NEUTRAL")]
zero_shot_correct = sum(1 for r, e in reviews if classify_zero_shot(r) == e)
few_shot_correct = sum(1 for r, e in reviews if classify_few_shot(r) == e)
print(f"Zero-shot: {zero_shot_correct}/{len(reviews)}")
print(f"Few-shot: {few_shot_correct}/{len(reviews)}")
# Expect: few-shot >= zero-shot (or equal if zero-shot is already perfect)