Few-shot prompting
Summary
Few-shot prompting means showing the model several examples of a task right inside the prompt, so that it repeats the required format and logic.
What it is
Usually a task can be given to the model without examples — that is zero-shot:
Determine the sentiment: "I liked everything about it"
But if the format is complex, it is better to show examples.
Zero-shot, one-shot and few-shot
| Approach | How many examples |
|---|---|
| Zero-shot | 0 examples |
| One-shot | 1 example |
| Few-shot | 2–5 examples |
Few-shot helps the model understand:
- the answer format;
- the style;
- how to handle difficult cases;
- what counts as correct.
Example
A prompt with examples:
Determine the sentiment of the review. Answer only "positive" or "negative".
Review: "The delivery was fast, everything is great"
Sentiment: positive
Review: "The item arrived broken"
Sentiment: negative
Review: "Overall fine, but the box is dented"
Sentiment:
The model is more likely to answer:
negative
How to build the examples
- use 2–5 examples;
- keep the format identical;
- show both typical and difficult cases;
- do not overload the prompt with extra material;
- the examples should resemble real requests.
Limitations
- the examples take up space in the context window;
- too many examples can confuse the model;
- the model may copy mistakes from the examples;
- for simple tasks few-shot is often unnecessary.