Zero-Shot vs Few-Shot Prompting
Gen AI · Prompt Engineering
Theory
Zero-shot prompting gives the model only an instruction and relies on what it learned in training to decide the format and behaviour. Few-shot prompting adds a handful of example input and output pairs before the real input, so the model copies the pattern. The examples are just extra context in the prompt: no training happens and the model itself does not change.
Few-shot helps most when the output format is unusual or strict, such as a company-specific label set, a fixed JSON shape or tricky edge cases like neutral reviews. A few diverse, correct examples usually beat many similar ones, and every example costs tokens on every call. Keep examples balanced, because the model tends to copy their patterns, including any bias towards one label.
Why we use it
It teaches the model your exact format and labelling rules in seconds, without collecting a training dataset or fine-tuning, which makes outputs more consistent and easier to parse.
When to use it
Start zero-shot for common tasks the model already handles well. Switch to few-shot when outputs drift in format or edge cases are handled wrongly. If you need hundreds of examples to get it right, fine-tuning may be the better tool.
How it works
- Write a clear zero-shot instruction
- Test it on real inputs
- Is the format and labelling consistent? Yes: Keep the zero-shot prompt. No: Add 2-5 diverse example pairs.
- Include at least one tricky edge case example
- Re-test and check that the labels are not skewed
- Use the prompt in production
Example
Few-shot prompt:
Classify sentiment as Positive/Negative/Neutral.
"Great service, fast delivery." -> Positive
"It broke after two days." -> Negative
"It arrived on Tuesday." -> Neutral
"Absolutely love this product!" -> ?
Model output: PositiveKey points
- Few-shot examples teach format and style without any retraining
- Most useful when the desired output structure is unusual or strict
- Use diverse, correct examples, including at least one edge case
- Returns diminish after a few well-chosen examples; each one costs tokens
- Unbalanced examples can bias the model towards one answer