Zero-shot vs Few-shot
Scenario
You ask a model to classify support tickets into 'billing', 'technical', or 'other'. Zero-shot gives 70% accuracy. A colleague adds three example classifications to the same prompt. Before you read on, predict: how much does accuracy change — and does retraining happen?
Make your prediction, then read on to understand why examples outperform instructions.
Mental model
Zero-shot is 'figure it out from the instructions alone'. Few-shot is 'here are three worked examples — now do the same thing'.
LLMs learn from patterns. A zero-shot prompt tells the model what to do in words. A few-shot prompt shows the model the input → output pattern directly. Examples activate the model's in-context learning ability, calibrating its output format, label vocabulary, tone, and edge-case handling — without any retraining. The model does not learn from the examples permanently; it pattern-matches them within the context window.
Deep dive
Zero-shot: you write the task instructions and give the input. No examples. The model relies entirely on its pre-training to decide how to format the output. It works well for common tasks like summarization, translation, and standard sentiment analysis — tasks the model has seen millions of examples of during training. It struggles with unusual output formats, custom label sets, and edge cases specific to your domain.
Zero-shot: instructions only. Works for common tasks; struggles with unusual formats or label sets.
Few-shot: you add 2–5 worked examples — (input, expected output) pairs — before the real query. The examples show the pattern rather than describe it. This is especially useful for custom output formats (structured JSON with your exact field names), non-obvious classification labels, tone matching, and tasks that are hard to describe in words but easy to show.
Few-shot: show, don't tell. Examples calibrate format, labels, and edge cases better than words can.
Example quality matters more than quantity. Two diverse, well-chosen examples beat ten repetitive ones. Rules for good examples: they should cover the range of input variation (including ambiguous cases), their output should exactly match the format you want, and each should be realistic — not a toy case. Repetitive examples teach the model nothing new.
Quality > quantity. Two to five diverse, realistic examples beat ten identical easy ones.
The cost trade-off: few-shot adds tokens to every API call — you pay for those example tokens on every request. For high-volume, simple tasks, zero-shot is the right economic choice. For complex or format-sensitive tasks, few-shot reduces retries and downstream validation errors, so the token cost pays for itself. **Start zero-shot. Measure failure modes. Add targeted examples only where zero-shot fails.**
Start zero-shot, measure failures, add examples only where needed. Each example costs tokens on every call.
Code examples
Zero-shot classification
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model='gpt-4o-mini',
messages=[
{'role': 'system', 'content': 'Classify the ticket: billing, technical, or other. '
'Reply with only the label.'},
{'role': 'user', 'content': 'My invoice shows a charge I did not authorize.'},
],
max_tokens=10,
temperature=0,
)
print(response.choices[0].message.content) # 'billing'
Zero-shot with a tight instruction. `max_tokens=10` enforces a short label. `temperature=0` maximizes consistency. Works well for obvious cases; fails on ambiguous tickets where the category depends on your custom rules.
Few-shot classification — examples as user/assistant pairs
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model='gpt-4o-mini',
messages=[
{'role': 'system', 'content': 'Classify each support ticket as: billing, technical, or other.'},
# Example 1
{'role': 'user', 'content': 'I was charged twice for last month.'},
{'role': 'assistant', 'content': 'billing'},
# Example 2
{'role': 'user', 'content': 'The API keeps returning 500 errors.'},
{'role': 'assistant', 'content': 'technical'},
# Example 3
{'role': 'user', 'content': 'Just wanted to say your team is great!'},
{'role': 'assistant', 'content': 'other'},
# Real query
{'role': 'user', 'content': 'My payment method was rejected even though my card is valid.'},
],
max_tokens=10,
temperature=0,
)
print(response.choices[0].message.content) # 'billing'
Examples are injected as alternating user/assistant turns — the model continues the pattern. Three examples cover all three categories. The real query is ambiguous (billing or technical?), but the examples teach the intended boundary.
Common mistakes
- Using examples that all look the same: Five examples that are all obvious billing tickets teach the model nothing about edge cases. Include diverse examples that cover ambiguous and hard cases — those are the ones zero-shot gets wrong.
- Adding more and more examples hoping for perfection: Few-shot has diminishing returns past about 8 examples, and each one costs tokens on every call. If you need 20 or more examples to get acceptable accuracy, the task likely needs fine-tuning, not a longer prompt.
Glossary
- zero-shot
- Giving the AI a task instruction and input with no examples, relying on its training to figure out the right output format and behavior.
- few-shot
- Showing the AI two to five worked examples of the exact input-to-output pattern you want, so it can match that pattern on new inputs.
- in-context learning
- The AI's ability to learn a new pattern or format just by seeing examples in the prompt, without any retraining of its weights.
Recall questions
- Explain the difference between zero-shot and few-shot prompting to a classmate.
- What are two common ways to include few-shot examples in a chat model call?
- When should you consider fine-tuning instead of adding more few-shot examples?
- If your zero-shot classifier works at 85% but fails specifically on sarcastic reviews, what few-shot examples would you add?
Questions & answers
Your zero-shot sentiment classifier gets 88% accuracy in testing. In production, edge cases around sarcasm drop it to 74%. What is the most cost-effective next step before fine-tuning?
Add few-shot examples targeted at the failure modes — two or three sarcastic reviews with the correct label, and two or three mixed-sentiment reviews. Targeted examples activate in-context learning for exactly the cases zero-shot gets wrong. This is cheaper and faster than fine-tuning if it closes enough of the gap.
Approach: Key word: targeted. Random easy examples do not help. Collect actual misclassified examples, pick the most representative ones, and add them as demonstrations.
A teammate proposes adding 20 few-shot examples to improve a support-ticket classifier. What concerns would you raise?
Three concerns: token cost — 20 examples adds 500–1,000 tokens to every API call permanently; diminishing returns — accuracy gains flatten past about 8 examples; context pressure — 20 examples plus the system prompt may use 30–40% of the context window, leaving less room for long tickets. Recommendation: audit which specific cases fail, add 3–5 targeted examples for those, and measure. If you still need 20+, benchmark fine-tuning instead.
Approach: Three dimensions: cost per call, diminishing accuracy returns, and context window pressure. The answer is not 'never use few-shot' — it is 'be surgical about it'.
Continue learning
Previous: Chat Completions API
Next: Chain-of-Thought