
What Is Few-Shot Prompting?
Few-shot prompting is the technique of including a small number of worked input-output examples directly in the prompt so the model infers the pattern you want and applies it to new input. It teaches by demonstration instead of description, and no training or fine-tuning is involved: the examples live in the prompt itself.
Key Takeaways
- Examples communicate format, tone, and edge-case handling far more precisely than instructions do. Showing three correct outputs beats describing them in a paragraph.
- Two to five well-chosen examples usually capture most of the gain. Quality and coverage of the examples matter more than quantity.
- Models imitate everything in the examples, including flaws. Inconsistent labels or sloppy formatting in your shots reproduce faithfully in the output.
- Few-shot prompting is inference-time only, which makes it the cheap, fast alternative to fine-tuning for teaching a model a task-specific pattern.
How It Works
The prompt is assembled as a short sequence of demonstration pairs, typically input then desired output, repeated a few times, followed by the real input. Language models are strong pattern completers, so when the context establishes a consistent mapping, the model continues it. This behavior is often called in-context learning: nothing about the model's weights changes, and the "learning" evaporates when the prompt ends. The approach was demonstrated at scale in OpenAI's 2020 GPT-3 paper, where a 175-billion-parameter model handled translation, question answering, and cloze tasks from in-context examples alone, with no gradient updates or fine-tuning [1]. The related phrase "few shot learning" predates modern LLMs and originally described training models from few labeled examples; in current practice the two phrases usually both point at this prompting technique.
Example selection is where the engineering lives. Good shots cover the distribution of real inputs, including the awkward cases: the empty field, the ambiguous entry, the input that should be refused. Ordering matters at the margins, and consistency matters a lot, since the model treats every detail of the examples as signal, down to whitespace and punctuation. What the model extracts from shots is subtler than it looks: a 2022 EMNLP study by Min et al. found that randomly replacing the labels in demonstrations barely hurt performance across 12 models including GPT-3, which suggests examples mostly teach format and input distribution rather than exact input-label mappings [2]. Production systems frequently make selection dynamic, using semantic search to retrieve the stored examples most similar to the incoming request and splicing those into the prompt.
Few-shot prompting stacks cleanly with other techniques. Shots can demonstrate chain-of-thought reasoning, not just final answers, which teaches both the procedure and the format. And because a fixed block of examples is a stable prompt prefix, prompt caching makes even a long example section cheap to resend on every call. For a many-shot prompt with 10,000 tokens of examples, Anthropic reported in 2025 that caching cuts cost by 86% and latency by 31% [3].
Example
A team extracts structured data from vendor invoices that arrive as messy text. Their instruction-only prompt kept producing drift: dates in mixed formats, currency symbols sometimes included, line items occasionally merged. They replaced most of the instructions with four worked examples, each showing a raw invoice snippet and the exact target JSON, deliberately including one invoice with a missing PO number (output: "po_number": null) and one duplicate line item (output: kept as two entries). Format errors mostly disappeared, because the model now copies a demonstrated pattern instead of interpreting prose. When a new failure mode shows up in production, the fix is usually adding one example that demonstrates the correct handling.
What People Get Wrong
The classic mistake is treating examples as decoration and letting them contradict the written instructions. When instructions say "output ISO dates" but an example shows "March 5, 2026," the model has to pick a side, and it often sides with the demonstration. Examples are the strongest signal in the prompt. Audit them like code: keep them consistent with each other and with the instructions, and update them when requirements change, or they become the bug.
FAQ
What is the difference between few-shot prompting and few-shot learning? In modern LLM usage they are effectively the same thing: conditioning a model with in-prompt examples, no weight updates. In the older machine-learning literature, few-shot learning meant training or adapting a model from a small labeled dataset. Context tells you which sense a writer intends.
How many examples should I include? Start with two or three and add only when evals show gaps. Returns diminish quickly, each shot costs tokens on every call, and a bloated example section can crowd out the actual task. If you find yourself needing dozens of examples, that is a signal to consider fine-tuning instead.
When does few-shot beat zero-shot? Whenever the output format is strict, the task convention is unusual, or edge cases need demonstrated handling. For tasks the model already does well from instructions alone, zero-shot is cheaper and examples add little beyond token cost.
Sources
- Brown et al., OpenAI. "GPT-3 performing tasks from in-context examples with no gradient updates." https://arxiv.org/abs/2005.14165. Accessed August 2026.
- Min et al., EMNLP 2022. "Random labels in few-shot demonstrations barely hurt performance across 12 models." https://arxiv.org/abs/2202.12837. Accessed August 2026.
- Anthropic. "Prompt caching savings for a 10,000-token many-shot prompt." https://claude.com/blog/prompt-caching. Accessed August 2026.
Related terms
Related Topics
Ready to build your product?

