Skip to content

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.

Gnome mascot

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

TechniqueExamplesGood forWatch out for
Zero-shot0Simple tasks, broad outputs, when flexibility is the goalLess control over format and style
One-shot1Establishing a format, simple classificationSingle example can overfit the model's output
Few-shot2-5Complex tasks, specific formats, consistent reasoningExamples can bias the model toward their specific patterns
Many-shot10+Very specific output formats, when the model needs to learn a patternUses 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

MistakeHow you notice itThe fix
Examples bias the modelModel classifies everything as the majority example's categoryBalance examples across categories. If you have 3 POSITIVE and 1 NEGATIVE example, the model skews POSITIVE
Examples are too specificModel only matches the exact pattern from examples, fails on variationsUse diverse examples that cover different phrasings, not just one template
Examples contradict the instructionsInstructions say "be concise" but examples are verboseThe model follows examples more strongly than abstract instructions. Make examples match instructions
Too many examplesContext window fills up, diminishing returnsStart 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)

Next: System Prompts & Role Assignment