What Is Few-Shot Prompting? Definition and Examples
Quick answer
Few-shot prompting explained: what it means, how to build a prompt with examples, what makes a good example, and how it differs from few-shot learning.
Few-shot prompting means including a small number of worked examples inside your prompt so a language model can see the pattern you want before it answers. You give a few input and output pairs, then a new input. The model copies the format, tone or labelling style without any retraining.
Key takeaways
- Few-shot prompting puts example input and output pairs in the prompt itself; the model's weights are not changed.
- It is most useful for fixing an output format, a label set or a tone.
- Good examples are relevant, diverse and clearly structured.
- Few-shot prompting is different from few-shot learning, which is a training-side idea.
On this page:
- What few-shot prompting means
- How it works, with code
- Where it is used
- Common mistakes and confusions
- Related terms
- Frequently asked questions
| Term | Examples in the prompt | Model weights change? |
|---|---|---|
| Zero-shot prompting | None, only an instruction | No |
| One-shot prompting | One example | No |
| Few-shot prompting | A handful of examples | No |
| Fine-tuning or few-shot learning | Examples used for training | Yes |
What does few-shot prompting mean?
It means teaching by demonstration inside the prompt. The term comes from research on GPT-3. In Brown et al.'s 2020 paper on arXiv, the authors test GPT-3 in the few-shot setting, where it is applied without any gradient updates or fine-tuning, with tasks and few-shot demonstrations specified purely via text interaction with the model.
Anthropic's documentation says the same practical thing for its own models. According to the Anthropic prompting documentation, examples are one of the most reliable ways to steer output format, tone and structure, and a few well-crafted examples (known as few-shot or multishot prompting) improve accuracy and consistency.
How does few-shot prompting work?
You list labelled examples, then add the new input and leave the answer blank. The model continues the pattern. Here is an illustrative sentiment-labelling prompt:
Review: Movie was dull
Sentiment: Negative
Review: Loved the songs
Sentiment: Positive
Review: Food was cold but staff were kind
Sentiment:With no examples, a model might answer with a full sentence. With two examples in front of it, the model has a pattern to copy, so a one-word label in the same style becomes the natural continuation. Test this on your own model. The snippet below builds such a prompt from a list. It needs no API call; it prints the text to send.
examples = [
("Movie was dull", "Negative"),
("Loved the songs", "Positive"),
]
new_input = "Food was cold but staff were kind"
prompt = ""
for text, label in examples:
prompt += f"Review: {text}\nSentiment: {label}\n\n"
prompt += f"Review: {new_input}\nSentiment:"
print(prompt)The Anthropic page lists three qualities of good examples: relevant (mirror your actual use case closely), diverse (cover edge cases and vary enough that the model does not pick up unintended patterns) and structured (wrapped in example tags).
Where is few-shot prompting used?
It is used for classification, extraction, rewriting and any task where the output format must stay consistent. An illustrative Indian case: an e-commerce team in Chennai tags customer messages written in mixed Tamil and English as delivery, refund or product. Three examples that mix the languages cover the edge case the "diverse" guidance describes, so the tags stay consistent.
Another case: an operations team asks for support-ticket summaries in a fixed three-line format. Two sample summaries in the prompt can do more than a long paragraph of instructions, though you should test on your own data.
What are the common mistakes and confusions?
- Mixing it up with few-shot learning. According to IBM (January 2024), few-shot learning is a machine learning framework in which a model learns by training on a very small number of labelled examples. Few-shot prompting does no training.
- Using examples that are all alike. If every example is positive, the model may lean towards positive.
- Picking examples that do not match real inputs. Use realistic messages, not tidy ones.
- Assuming a fixed number is right. No single count suits every task. The Anthropic page suggests including 3 to 5 examples for best results with its models; treat that as a starting point and compare.
Which terms are related?
Few-shot prompting pairs well with chain of thought prompting, where the examples include reasoning steps. For wider context, see what prompt engineering is, how to write effective AI prompts and prompt engineering vs RAG vs fine-tuning.
Next step
Pick a small labelling task, write a zero-shot prompt, then add two or three varied examples and compare the outputs on ten real inputs. More ideas are in AI prompt examples.
Frequently asked questions
What is few-shot prompting?
Few-shot prompting means placing a small number of input and output examples in the prompt so the model can follow the pattern on a new input. The model is not retrained; the examples only guide its output.
What is the difference between zero-shot and few-shot prompting?
Zero-shot prompting gives only an instruction and no examples. Few-shot prompting adds a few worked examples before the new input, which helps fix the format, tone or labels you want.
How is few-shot prompting different from few-shot learning?
Few-shot prompting puts examples in the prompt and changes no weights. Few-shot learning, as IBM describes it, is a machine learning framework where a model is trained on a very small number of labelled examples.
What makes a good few-shot example?
Anthropic's guidance says examples should be relevant to your real use case, diverse enough to cover edge cases without creating unintended patterns, and clearly structured, for example wrapped in example tags.
Does few-shot prompting change the model?
No. In the GPT-3 paper, the model is applied without gradient updates or fine-tuning, with demonstrations given purely through text. The examples affect only that one request.