Few-shot prompting prepends 2-8 worked input-output examples to the query so the model can imitate the pattern through in-context learning, with no weight updates.
Imagine asking a new intern to label customer feedback. If you just say 'label these,' they will probably invent their own categories. So you show them three already-labeled examples first: this one is positive, this one is negative, this one is neutral. Now they know what shape your labels take and can copy the pattern on the next ten. Few-shot prompting is the same trick with a language model. You drop in two to eight worked examples right before the actual question, and the model imitates the demonstrated pattern. The model is not being trained or retrained. It is just reading the examples in the same prompt and matching the shape. The training all happened earlier. This is on the fly imitation.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Few-shot prompting is one of the most useful and most misunderstood techniques in the prompt engineer's toolkit. The question that matters in production is what the model is doing with those examples. That determines when to use the technique and when to reach for something else.
The model is doing in-context learning. In-context learning is a real, measurable property of transformer language models. Once you understand it as pattern completion within a single call (rather than as training), every operational decision around few-shot prompting becomes clearer.
What few-shot is, and what 'in-context learning' means
Few-shot prompting includes 2-8 worked input-output examples (demonstrations) in the prompt, immediately before the input the model should respond to. A standard shape: an instruction, then three labeled examples, then the new input. The model is expected to imitate the demonstrated pattern in its response to the new input.
The mechanism is in-context learning. Inside the forward pass, the transformer attends to the demonstrations the same way it attends to any other tokens in the prompt. The patterns it picks up there bias the next-token distribution for the answer. This is just attention doing what attention does. The GPT-3 paper (Brown et al. 2020) named this in-context learning: the model picks up the task from the context, inside the forward pass.
No weight update happens. After the call returns, the model has no memory of the demonstrations. The next API call starts blank. This separates few-shot from any form of fine-tuning, where examples are compressed into weight changes that persist.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- GitHub Copilot adds snippets from files open in neighboring editor tabs to its prompt, so completions follow the project's own coding style. This retrieved context works much like dynamic demonstrations.
- Anthropic recommends 3-5 relevant, diverse examples for Claude, wrapped in XML example tags so the model can tell them apart from instructions.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you pick which few-shot examples to include for a given task?
Start with 3-5 diverse hand-picked examples that span input types. If quality is uneven, switch to dynamic selection, which retrieves the nearest examples by embedding similarity to the current query.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Believing the model is being fine-tuned by your few-shot examples. Nothing is updating in the weights. The model is doing in-context pattern matching for that one call. It forgets the examples on the next request.
60 second bullets to scan on the way to the call.
Define few-shot prompting in one sentence; what the 'few' counts
What in-context learning is and why no weight update happens
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.