Few-shot prompting means adding a few worked examples to a prompt before the real task. The model reads the examples, spots the pattern and applies it to the new input.
“Few” usually means two to five. One example is called one-shot. No examples is zero-shot prompting.
The idea was popularized by the GPT-3 paper, Language Models are Few-Shot Learners (2020). It showed that a large model can pick up a new task from examples in the prompt, with no extra training.
A few-shot example
Say I want short product tags in a fixed style. Describing the style takes a paragraph. Showing it takes three lines.
Write three tags for each product. Lowercase, hyphenated, no brand names.
Product: Waterproof hiking boots with a Vibram sole
Tags: hiking-boots, waterproof, trail-gear
Product: Insulated steel water bottle, 750 ml
Tags: water-bottle, insulated, travel
Product: Merino wool base layer for cold weather
Tags:
The model fills in the last line in the same format. Without the examples, I often get capital letters, extra words or a sentence before the tags.
What the examples teach
Examples carry more than instructions do. The model copies whatever they share.
| The examples show | The model copies |
|---|---|
| Output format | Length, layout, punctuation |
| Labels | The exact category names you use |
| Tone | Formal, casual or your house style |
| Edge cases | How to handle tricky inputs |
That cuts both ways. If every example is short, answers will be short. If every example ends in the same label, the model may lean toward that label.
Tips for good examples
- Use real inputs, pick examples that look like the data you will send.
- Cover different cases, lengths and labels.
- Use the same field names and separators every time.
- One tricky example teaches more than three easy ones.
- Models can lean toward the last example, so mix labels.
When to use few-shot prompting
Start with a clear zero-shot prompt. Add examples when the format drifts, the labels are your own, or the style is hard to describe.
Examples add tokens to every message. Save them once in a system prompt or a saved prompt in a prompt library so you don’t paste them each time.
For maths and logic, examples that show the working are even stronger. That technique is called chain-of-thought prompting.
