deep · 5 min
Few-shot prompting
Putting worked examples in the prompt so the model copies the pattern.
updated 23 Sept 2026
Here's a prompt that sorts support tickets. Instead of describing the
labels, it shows three tickets with their answers, written as earlier
turns of the conversation (the chat API lets us write the
assistant replies ourselves), and then asks about a fourth:
"messages": [
{"role": "user", "content": "I was charged twice this month."},
{"role": "assistant", "content": "billing"},
{"role": "user", "content": "The export button does nothing."},
{"role": "assistant", "content": "bug"},
{"role": "user", "content": "How do I change my login email?"},
{"role": "assistant", "content": "account"},
{"role": "user", "content": "The app crashes when I upload a PNG."}
]
What we expect back is bug: one lowercase word, like every reply
before it.
That's few-shot prompting: put a few worked examples in the prompt and the
model carries on the pattern. Nothing gets trained, no weights change.
(The other common way is to put the examples in the system prompt,
wrapped in tags like <example> so they don't blur into the instructions;
see XML tags.)
Simple enough. But what did the model actually pick up from those three examples? Let's guess, and then check the guess.
First guess: it learned the right answers
The obvious story is that the model studied the three tickets, saw which label went with which, and learned the task from them. The name feeds that story. The GPT-3 paper in 2020 called it in-context learning, because a model with its weights frozen got better at a new task just from examples in the prompt. (The authors were careful, though. They left open whether the model learns something new right then, or recognises a pattern it already saw in training.)
Here's the test that settles it. Take few-shot prompts for classification
and swap the correct labels for random ones. "I was charged twice" now
says account. If the model learns from the right answers, accuracy
should fall apart.
It barely moved. Across 12 models up to GPT-3, random labels cost about 0 to 5 points. And random-label examples still beat having no examples at all.
So what were the examples doing?
If not teaching the right answers, then what? Three things, it seems:
- The set of possible answers. It's one of
billing,bugoraccount, not a sentence. - What inputs look like. Short tickets, not essays.
- The format. Input, then a one-word answer. Even random English words as labels did much better than no labels, because that shape was still there.
So the model mostly already knew how to sort tickets. The examples told it which task we meant and what shape the answer should take.
Before we push that too far: the gap reached almost 14 points on one dataset, labels that were deliberately flipped (not just shuffled) did hurt in later work, and the test only covered classification and multiple choice. "Correctness doesn't matter" is the wrong lesson. "Format and coverage are what the model picks up first" is closer.
Second guess: so the order doesn't matter either
If the model mainly reads off the format, shuffling our three examples shouldn't change much. It can change a lot. On a GPT-3-era model, four sentiment examples tried in every possible order gave accuracy anywhere from near a coin flip to near the best scores of the time. Nothing changed but the order.
Three leanings explain most of it. The model leans towards whichever answer shows up most in the examples. It leans towards the answers near the end: examples ordered positive, positive, positive, negative led to nearly 90% "negative" answers. And it leans towards answers that are common in its training data. More examples and bigger models didn't make the swings go away in that study.
For our ticket prompt, that means: balance the labels, vary the inputs, and don't end on a run of the same answer.
The model copies more than you meant, too. If every example is short, answers get short. If every example mentions a price, the model may invent one. Whatever the examples share gets copied, so make them different in every way except the thing you want copied. And keep them in line with your instructions; if the instructions say "one word" and an example reply is a full sentence, the model has to pick one.
What if we show it thousands?
With million-token windows, "a few" became optional. In one 2024 study, Gemini was given hundreds or thousands of examples, up to a million tokens of them. Results kept improving well past a few examples, often peaking only at hundreds of thousands of tokens.
And here the random-labels story flips. With a few examples, the model sticks to what it already believes. Rotate the sentiment labels (positive now means negative, and so on) and few-shot accuracy is poor. With enough rotated examples, it climbed close to normal. At that scale the labels really do teach.
On translating into a couple of low-resource languages, many examples in the prompt came close to fine-tuning. The catch is the bill. Fine-tuning pays once. Examples in the prompt get paid for on every call (token pricing), and caching the repeated part softens that without removing it. More also stopped helping at some point: on two hard math and science benchmarks, results dropped after about 125 examples.
And with reasoning models?
Everything so far was measured on models that answer straight away. For
reasoning models, the advice from the vendors (as of
2026-09) splits. OpenAI says try no examples first and add them only if
the output isn't right, and warns that examples which don't match your
instructions can make things worse. Anthropic still calls examples one of
the most reliable ways to steer format and tone, suggests 3 to 5, and
suggests showing the reasoning inside <thinking> tags in the examples
so the model copies that style too (the older version of that idea is
chain-of-thought prompting).
Those fit together better than they look. Both treat examples as a way to pin down format and style. Neither says examples make a strong model smarter.
What nobody has measured is how much of the fragility above survives on current models. The random-label and ordering tests ran on 2021 and 2022 models, before instruction tuning was standard, and the vendor advice for 2026 comes without numbers. So for our ticket sorter, the safe move is boring: try a few orderings and label mixes on a small test set, and don't trust one lucky run.
Further reading
- Language Models are Few-Shot Learners, Brown et al. (OpenAI), 2020. The GPT-3 paper, where zero-, one- and few-shot got their names.
- Rethinking the Role of Demonstrations, Min et al., 2022. The random-labels test. Short and changes how you think about examples.
- Calibrate Before Use, Zhao et al., 2021. Why example order swung accuracy so much, and the three leanings behind it.
- Many-Shot In-Context Learning, Agarwal et al. (Google DeepMind), 2024. What happens with thousands of examples, and how it compares to fine-tuning.
- Prompting best practices, Anthropic docs. Current advice on picking and wrapping examples, including examples with thinking.
- Reasoning best practices, OpenAI docs. The case for starting with no examples on reasoning models.