Few-shot prompting is including a small number of worked examples in a prompt, each showing an input and the desired output, so the AI model learns the pattern and applies it to a new input. It is one of the most reliable ways to control format, tone and labelling without retraining a model.
Key takeaways
- “Few-shot” usually means around 2–10 examples in the prompt.
- The model learns from examples during the conversation, called in-context learning; its weights do not change.
- It is ideal for custom labels, house style and precise output formats.
- Example quality, variety and order all affect results.
- It costs more tokens than zero-shot prompting.
Few-shot prompting explained in simple terms
When training a new team member to categorise support tickets, you do not just describe the categories. You show them a few real tickets and how each was tagged. They pick up the pattern quickly, including subtle rules you never wrote down. Few-shot prompting does the same for an AI model.
Where it came from
The 2020 paper introducing GPT-3, titled “Language Models are Few-Shot Learners”, showed that large language models could perform new tasks from just a few examples in the prompt, without any retraining. This in-context learning ability became central to how people use AI models.
A worked example: custom ticket labels
A company uses its own categories: Billing, Access, Bug, Feature Request.
“Classify each support message into one category: Billing, Access, Bug or Feature Request.
Message: I was charged twice this month.
Category: Billing
Message: The export button does nothing when I click it.
Category: Bug
Message: Can you add a dark mode?
Category: Feature Request
Message: I can’t log in after resetting my password.
Category: Access
Message: The invoice PDF shows the wrong GST number.
Category:”
The model will likely answer “Billing”. The examples taught it that invoice problems are Billing, not Bug, a distinction a zero-shot prompt might miss.
Zero-shot vs few-shot vs fine-tuning
| Approach | How the model learns | Cost | Best for |
|---|---|---|---|
| Zero-shot | Instructions only | Lowest | Common, clear tasks |
| Few-shot | Examples in the prompt | More tokens per request | Custom formats, labels, style |
| Fine-tuning | Training on many examples | Upfront training cost | High volume, very consistent behaviour |
A common path is: start zero-shot, add few-shot examples if results are inconsistent, and consider fine-tuning only if prompts become very long or volume is very high.
Best practices
- Use realistic examples that look like real inputs.
- Cover the variety: include each category and tricky edge cases.
- Keep formatting identical across examples so the pattern is obvious.
- Balance the examples: too many of one label can bias outputs toward it.
- Watch the order: models can be influenced by the most recent examples, so mix categories.
- Combine with instructions: examples plus a clear rule set work better than either alone.
- Use correct examples: the model will copy mistakes too.
Few-shot with reasoning
For complex problems, examples can include the reasoning steps, not just the answer. This is few-shot chain-of-thought, shown in a 2022 Google paper to improve performance on multi-step maths and logic tasks. See chain-of-thought.
Choosing examples dynamically
In production systems, examples are often selected automatically for each request: the system finds the most similar past examples using embeddings and inserts them into the prompt. This keeps prompts short while making examples highly relevant.
Limitations
- Longer prompts increase cost and latency.
- Poor, biased or unbalanced examples lead to poor outputs.
- Models may copy surface patterns, such as length or wording, too closely.
- Examples take up space in the context window.
- Few-shot cannot add knowledge the model lacks; for facts, provide source documents.
