Few-shot prompting means putting a handful of worked examples, each an input with the exact output you want, into the prompt before the real input, so the model copies the pattern instead of guessing it. It is the most reliable way to control output format, labels and tone without fine-tuning, and 3 to 5 varied examples is the usual starting point.
Where the term comes from
The term was popularised by the 2020 GPT-3 paper, Language Models are Few-Shot Learners (Brown et al.). The authors showed that a 175-billion-parameter model could perform new tasks from "few-shot demonstrations specified purely via text interaction with the model", with no gradient updates or fine-tuning. The paper's terms are still the standard ones:
| Term | What the prompt contains | Good for |
|---|---|---|
| Zero-shot | Instruction only | Tasks the model already does well and where any reasonable format is fine |
| One-shot | Instruction plus one example | Showing an exact output format |
| Few-shot | Instruction plus several examples | Custom labels, consistent tone, edge cases, structured output |
OpenAI's guide describes the effect: "The model implicitly 'picks up' the pattern from those examples and applies it to a prompt."
A worked few-shot prompt
Say you want support tickets sorted into your own categories, with a fixed output format. Zero-shot, a model might reply "This looks like a billing issue" one time and "Category: Payments" the next. With examples:
Classify each support ticket as one of: billing, bug, account, feature-request.
Reply with the label only, in lowercase.
<examples>
<example>
Ticket: I was charged twice for October.
Label: billing
</example>
<example>
Ticket: The export button does nothing in Firefox 131, works in Chrome.
Label: bug
</example>
<example>
Ticket: How do I change the email address on my login?
Label: account
</example>
<example>
Ticket: Would love a dark mode. Also, my card expires next month, where do I update it?
Label: billing
</example>
</examples>
Ticket: Can you add an option to export as PDF?
Label:
The instruction states the rules; the examples show them applied. The fourth example does extra work: it contains a feature request and a billing question, and shows that the actionable billing part wins. Ambiguous cases are where examples earn their place, because they settle decisions the instruction didn't spell out.
How many examples to use
Anthropic's prompting guide recommends: "Include 3–5 examples for best results." Treat that as a starting range to test, not a law. Every example costs tokens on every request (see how many tokens a word is), so each one should cover a case the others don't. If you need many examples to get acceptable results across thousands of requests, that is the point where fine-tuning or a different approach becomes worth comparing.
Paste your full prompt, examples included, into the token counter to see what the examples add to each call.
What makes a good example
Anthropic lists three properties. Make examples:
- Relevant: "Mirror your actual use case closely." Use real inputs (anonymised) rather than tidy invented ones.
- Diverse: "Cover edge cases and vary enough that Claude doesn't pick up unintended patterns." OpenAI's guide says the same: "show a diverse range of possible inputs with the desired outputs."
- Structured: wrap them in tags such as
<example>inside<examples>so the model can tell examples apart from instructions and from the real input.
"Unintended patterns" is the common failure. If all your examples are one sentence long, outputs get short. If every example's answer is bug except one, the model leans towards bug. If every example starts "Hi team,", so will the output. Vary everything except the thing you want copied.
What research says about examples
Two findings are useful in practice:
- Format matters more than you'd expect, and correct labels less. Min et al. (2022) found that "randomly replacing labels in the demonstrations barely hurts performance" on classification and multiple-choice tasks across 12 models. What helped was showing the set of possible answers, the kind of input text, and the overall format. The takeaway is not that wrong labels are fine; it's that the examples' shape carries a lot of the signal, so get the format exactly right.
- Order can change results. Zhao et al. (2021) reported that with GPT-3, "the order of the training examples can cause accuracy to vary from near chance to near state-of-the-art", and traced this partly to a bias towards answers that appear near the end of the prompt. It's cheap insurance to shuffle examples and avoid putting several of the same label last.
Both papers studied earlier models, so treat them as reasons to test your own prompt rather than as fixed rules.
Few-shot prompting with reasoning models
Models that think before answering need less hand-holding on how to solve a problem. OpenAI's guide says reasoning models "will provide better results on tasks with only high-level guidance", while GPT models "benefit from very precise instructions". Examples remain useful for output format either way. Anthropic's guidance for extended thinking is that "worked examples in your prompt shape how Claude approaches similar problems in its own thinking blocks", and it suggests presenting each as the problem, the method to apply, and the expected answer.
Where to put the examples
- In an API call: OpenAI suggests examples typically go in the
developermessage, as a section after the instructions. Anthropic's guidance for Claude focuses on wrapping them in tags so they stay distinct from instructions and input. The system prompt vs user prompt article covers which belongs where. - In a chat interface: put them in your message before the actual request, clearly separated, and say "Follow the format of the examples."
- After long documents: Anthropic recommends placing long documents near the top of the prompt, above the query, instructions and examples.
If the model still ignores your examples
Check that the real input is formatted exactly like the example inputs, down to the label prefix (Ticket: and a trailing Label: above). Make sure no example contradicts the instruction, because the model will often follow the example. If outputs drift towards one answer, count the labels in your examples and balance them. And if the task needs judgment the examples can't capture, state the rule in words alongside them; the guide to writing a good prompt covers the instruction side.
Frequently asked questions
- What is the difference between zero-shot, one-shot and few-shot prompting?
- The number of worked examples in the prompt. Zero-shot gives only the instruction. One-shot adds a single input and its correct output. Few-shot adds several, typically 2 to 5. More examples show the pattern more clearly but make every request longer and more expensive.
- Is few-shot prompting the same as fine-tuning?
- No. Fine-tuning changes the model's weights by training it on many examples. Few-shot prompting changes nothing in the model: the examples are just part of the text you send, and the model follows the pattern for that request only. That is why few-shot works with any model you can prompt, and why the examples must be sent again with every request.
- Do few-shot examples work with reasoning models?
- They still help with output format, but they matter less for steering the reasoning itself. OpenAI's guide notes that reasoning models do better with high-level guidance than with very precise instructions. Anthropic's guidance says examples still shape how Claude approaches similar problems when extended thinking is on, and suggests presenting each as a problem, the method, and the expected answer.
- Why does the model copy the wording of my examples?
- Because examples are the strongest signal in the prompt. If every example is short, starts the same way or covers the same topic, the model treats that as part of the task. Vary length, phrasing and content across examples, and state in the instruction which features matter.
Sources
- Brown et al. (2020) — Language Models are Few-Shot Learners
- Claude Docs — Prompting best practices (Use examples effectively)
- OpenAI — Prompt engineering guide
- Min et al. (2022) — Rethinking the Role of Demonstrations: What Makes In-Context Learning Work?
- Zhao et al. (2021) — Calibrate Before Use: Improving Few-Shot Performance of Language Models