Sometimes the clearest way to tell a model what you want isn't to explain it — it's to show it. That's the entire idea behind few-shot prompting: instead of describing a task in the abstract, you give the model a small number of worked examples directly in the prompt, and let it infer the pattern. It's one of the simplest and most reliable prompt engineering techniques available. Here's how it works.
The Basic Definition
Few-shot prompting means including a small number of examples — typically somewhere between two and five — of the task you want performed, directly within the prompt, before asking the model to complete a new instance of that same task. The model doesn't need any retraining; it simply uses the examples as a live reference for what "correct" output looks like, then applies that pattern to your actual request.
The "few" refers to the number of examples provided — a handful, as opposed to zero (zero-shot prompting, covered in the previous post) or one (one-shot prompting, a related variant using just a single example).
A Concrete Example
Zero-shot version: "Classify the sentiment of this review as positive, negative, or neutral: 'The food was cold and the service was painfully slow.'"
Few-shot version:
Review: "Absolutely loved the atmosphere and the staff were wonderful."
Sentiment: Positive
Review: "It was fine, nothing special but nothing bad either."
Sentiment: Neutral
Review: "The food was cold and the service was painfully slow."
Sentiment:
By showing two labeled examples first, the prompt makes the exact expected format, label vocabulary, and classification standard explicit — the model doesn't have to guess whether you want "Negative" or "negative" or "1 star" or a longer explanation. It just follows the demonstrated pattern.
Why Few-Shot Prompting Works
This connects directly to a genuinely important LLM capability called in-context learning — the ability of a model to pick up a pattern from examples given within a single prompt, without any actual retraining or parameter updates happening. The model's underlying weights don't change at all; instead, the examples become part of the context the model attends to (via the self-attention mechanism covered earlier in this series), heavily influencing the probability distribution over what a "correct" continuation should look like.
In effect, the examples narrow the space of plausible next tokens far more precisely than a written instruction alone can. A description like "classify as positive, negative, or neutral" still leaves room for interpretation; two or three labeled examples remove almost all of that ambiguity by demonstration rather than explanation.
Why Examples Often Beat Explanations
There's a simple reason few-shot prompting tends to outperform a purely descriptive instruction: language is often more ambiguous than a direct example. Explaining a desired tone, format, or level of detail in words leaves room for interpretation; showing the model an actual instance of that tone, format, and detail level removes the guesswork almost entirely. This is especially true for:
- Precise formatting — showing exactly how you want a table, JSON structure, or citation style laid out is far more reliable than describing it
- Subtle style or tone matching — demonstrating the voice you want (formal, casual, technical, playful) is often far more effective than trying to describe it abstractly
- Domain-specific conventions — internal company terminology, unusual classification schemes, or non-standard formats that the model has no way to infer from general knowledge alone
How Many Examples Do You Actually Need?
There's no universal number, but a few practical guidelines tend to hold:
- Two to five examples is the typical sweet spot for most tasks — enough to establish a clear pattern without needlessly bloating the prompt
- More examples generally help with harder or more nuanced tasks, up to a point of diminishing returns
- Diversity among examples matters — if all your examples look too similar, the model may overfit to superficial features rather than the actual underlying pattern you're trying to demonstrate
- Order can matter too — models can be somewhat sensitive to the sequence of examples, and in some cases the most recent examples carry slightly more influence
Best Practices for Writing Good Few-Shot Examples
- Keep examples consistent in format. Every example should follow the exact same structure as the one you eventually want applied to your real input — inconsistent formatting across examples can confuse rather than clarify the pattern.
- Cover the range of cases you care about. If you're classifying sentiment, include a genuinely positive, negative, and neutral example — not three examples that are all subtly negative — so the model sees the full boundary of the task, not just one slice of it.
- Keep examples relevant and high quality. Since the model is directly pattern-matching against what you show it, a sloppy or inconsistent example can actively degrade output quality rather than improve it.
- Watch prompt length and cost. Since examples count as prompt tokens (as covered in the tokens and pricing posts earlier in this series), more examples means a longer, more expensive prompt — and one that eats into the model's context window, leaving less room for other content.
Few-Shot vs. Zero-Shot: When to Use Which
| Aspect | Zero-Shot | Few-Shot |
|---|---|---|
| Examples provided | None | A handful (typically 2–5) |
| Best for | Common, clearly-describable tasks | Format-sensitive, nuanced, or unusual tasks |
| Prompt length | Shorter | Longer |
| Reliability on niche tasks | Can be inconsistent | Generally more reliable |
| Effort required | Minimal | Requires crafting good, representative examples |
A useful rule of thumb: start with zero-shot for simplicity, and add few-shot examples specifically when the output isn't matching the format, tone, or standard you actually need.
Few-Shot Prompting vs. Fine-Tuning
It's worth distinguishing few-shot prompting from fine-tuning, since both involve "teaching" a model through examples, but in very different ways:
- Few-shot prompting provides examples at inference time, within a single prompt — no permanent change to the model, and the examples only apply to that specific conversation.
- Fine-tuning involves additional training on a larger dataset of examples, actually updating the model's parameters — a permanent, more resource-intensive change that persists across all future uses of that fine-tuned model.
Few-shot prompting is the fast, flexible, zero-setup option; fine-tuning is the heavier-weight approach reserved for cases where you need consistent, specialized behavior at scale, beyond what examples in a single prompt can reliably achieve.
The Bottom Line
Few-shot prompting works by showing a language model a handful of worked examples directly within the prompt, letting it infer the desired pattern through in-context learning rather than through an abstract written description. It's especially useful for tasks involving precise formatting, subtle tone, or domain-specific conventions that are hard to fully capture in words alone. It costs a bit more in prompt length and effort than zero-shot prompting, but for tasks where consistency and precision matter, a few well-chosen examples often do more to steer a model's output than any amount of additional explanation.