Describing exactly what you want is hard. Showing it is easy. Few-shot prompting means including a few examples of input and desired output in the prompt so the model can copy the pattern.
The technique became famous with the 2020 GPT-3 paper, Language Models are Few-Shot Learners, which showed that large models could perform new tasks from just a few examples, without any retraining.
Zero-shot vs. few-shot
- Zero-shot: “Classify the sentiment of this review.”
- Few-shot: the same instruction, followed by three labelled reviews, then the new one.
Few-shot prompts produce more consistent formats and handle edge cases better.
A template
Classify each customer message as BILLING, TECHNICAL or OTHER.
Message: “I was charged twice this month.” → BILLING Message: “The app crashes when I upload a photo.” → TECHNICAL Message: “Do you have an office in Berlin?” → OTHER
Message: “[new message]” →
Rules for good examples
- Cover the variety you expect, including tricky cases.
- Balance the labels — if most examples share one answer, the model leans toward it.
- Keep the format identical across examples.
- Use realistic inputs, not idealized ones.
- Three to five examples are usually enough; more costs tokens without always helping.
When to use it
- Extracting fields into a fixed structure
- Matching a brand’s tone of voice
- Classification and tagging
- Converting between formats
When it is not enough
If you need hundreds of examples to get reliable results, consider fine-tuning a model instead, or combining prompts with validation code that checks the output format.
A worked example: classifying customer feedback
Suppose you want to sort feedback into categories. A few-shot prompt might look like this:
Classify each message as Billing, Bug, Feature request or Praise. Answer with the category only.
Message: “I was charged twice this month.” → Billing Message: “The app crashes when I upload a photo.” → Bug Message: “Please add a dark mode.” → Feature request Message: “Your support team was fantastic!” → Praise
Message: “Export to PDF stopped working after the update.” →
The examples show the model the exact categories, the output format (a single label) and the boundary between similar cases — here, a broken feature is a Bug, not a Feature request.
Choosing examples well
- Cover each category at least once.
- Include tricky cases near category boundaries.
- Vary length and style so the model doesn’t copy superficial features.
- Keep the order mixed so the model doesn’t learn to favor the last label.
- Test on new examples you didn’t include in the prompt to check it generalizes.
The research behind it
The term “few-shot learning” in language models became widely known with OpenAI’s 2020 GPT-3 paper, Language Models are Few-Shot Learners, which showed that large models could perform new tasks from a handful of examples in the prompt, without updating their weights. This ability — often called in-context learning — is now a basic tool of prompt design.
Common mistakes
- Using examples that are all very similar, so the model can’t generalize.
- Including examples with errors, which the model will copy.
- Mixing formats between examples.
- Forgetting to show the “edge case” that matters most to you.
Few-shot plus instructions
Examples work best combined with a short instruction stating the task and output format. The instruction tells the model what to do; the examples show how.
What to watch next
- Automatic selection of the best examples for each query.
- Long-context models that can use many more examples.
- Comparisons between few-shot prompting and fine-tuning for production tasks.
- Structured output features that reduce the need for format examples.
Key takeaways
- Few-shot prompting shows the model examples of the input and desired output.
- Examples teach format, categories and boundaries better than descriptions alone.
- Choose diverse examples, including tricky cases, and test on new inputs.
- GPT-3 popularized the idea of learning tasks from examples in the prompt.
- For large-scale or highly specific tasks, fine-tuning may work better.
Frequently asked questions
How many examples should I use?
Often three to five are enough. Add more for complex tasks, watching cost and context length.
What is zero-shot prompting?
Asking the model to do a task with instructions only, without examples.
When should I fine-tune instead?
When you need consistent results on a narrow task at scale, or the behavior can’t be captured with a few examples.