Few-shot prompting is a technique in which a handful of worked examples of a task are included in the prompt so that a language model can infer the pattern and apply it to a new input. The examples, often called shots or demonstrations, show the format and the kind of judgment wanted. Unlike fine-tuning, the model’s weights do not change: the learning happens inside the prompt at run time, a capability called in-context learning. It is one of the core methods of prompt engineering for large language models.
Origin
Few-shot prompting became widely known through the 2020 GPT-3 paper, whose title announced that language models are few-shot learners. The authors evaluated the model with zero, one and a few examples in the prompt and found that results generally improved with more examples and with larger models. The finding changed practice: instead of collecting thousands of labeled items to train a classifier, developers could often write several examples and obtain useful behavior at once.
How it works
A few-shot prompt typically has three parts: an instruction, several example input-output pairs and the new input to be processed. For instance, a prompt might state that the task is to turn a product review into a one-word sentiment, then show three reviews with labels, and finish with a fourth review without a label. The model continues the pattern and supplies the missing label. Researchers think the examples help in several ways: they clarify the task, set the output format, signal the label set and sample the distribution of inputs.
Choosing examples
- Cover the range: include examples of every category and some difficult cases.
- Be representative: use inputs that resemble real data in length and style.
- Keep the format consistent: identical layout across examples helps the model copy it.
- Balance labels: a skewed set can bias the model toward the majority label.
- Mind the order: the sequence of examples can change results, and examples placed last often have more influence.
- Use quality: correct, clear examples are safest, even if format matters most.
- Select dynamically: retrieve the examples most similar to the current input from a larger bank, a method related to semantic search.
Number of examples
Accuracy usually rises with the first few examples and then levels off. Three to eight examples are common, though tasks with many categories may need more. Long prompts raise cost and delay, and they use up the context window, so teams test how many examples are worth including. Some modern systems accept dozens or hundreds of examples, called many-shot prompting, which can approach the effect of fine-tuning for some tasks.
Combining with reasoning
Examples can include worked reasoning, not only final answers. This is the idea behind chain-of-thought prompting, where each example shows the steps to a solution, encouraging the model to reason in the same way on a new problem. Few-shot examples can also demonstrate when to refuse, how to cite sources or how to use a tool.
Strengths
- Needs no training and little data.
- Quickly adapts a model to a new format or domain.
- Gives more consistent outputs than zero-shot prompting for specialized tasks.
- Is easy to edit, since changing an example changes behavior immediately.
Limitations
- Sensitivity: order, wording and selection of examples can change accuracy a great deal.
- Context cost: examples consume tokens on every request.
- Overcopying: the model may imitate surface features of examples, such as length or names.
- Bias: unbalanced or stereotyped examples can skew results.
- Ceiling: complex tasks may still require fine-tuning.
- Leakage: examples drawn from real customers may expose private data.
A worked example
A logistics company wants to extract the city and date from free-text delivery notes. The prompt says: extract the destination city and delivery date as JSON. It then shows three notes with their JSON results, including one note that has no date and returns null for it. A fourth note, left unlabeled, follows. The model returns correctly formatted JSON, including a null for a missing date, which it learned from the third example. A zero-shot version had returned sentences instead of JSON.
Many-shot and dynamic approaches
As context windows have grown, developers have begun to include dozens or even hundreds of examples, an approach called many-shot prompting. Studies report that accuracy can keep rising well beyond the handful of examples used in early work, especially on tasks with unusual formats or many categories. A related method keeps a large bank of labeled examples and selects the few most relevant to each new input by measuring similarity, so that every request receives tailored demonstrations. This blends prompting with ideas from retrieval and can match fine-tuned systems at lower setup cost.
Why examples help, and what research shows
Explanations of in-context learning remain an active research topic. Some studies find that the model uses examples mainly to recognize which task is wanted and what the output should look like, drawing on skills it already has. Others show that large models can pick up genuinely new input-output mappings from the prompt, suggesting a kind of learning at inference time. Either way, the practical lesson is consistent: examples work best when they are clear, varied and formatted consistently, and results should always be verified on held-out data rather than assumed.
Testing a few-shot prompt
Teams compare candidate prompts on a labeled validation set, varying the number, order and choice of examples. They check that the examples themselves are not included in the test data, which would inflate scores, and they report results from several runs to account for randomness. When behavior drifts after a model update, the same test set shows whether the examples still do their job. Keeping the examples in version control with notes on why each was chosen makes later maintenance far easier.
Related concepts
Few-shot prompting sits alongside role-based prompting, prompt chaining and the design of a reusable prompt template that holds the examples.
FAQs
Is few-shot prompting the same as fine-tuning? No. Few-shot prompting places examples in the input and changes no model weights, while fine-tuning updates the weights through additional training.
How many examples are enough? Usually a handful, and the best number is found by testing.
Do the examples have to be perfect? Quality helps, but the format and range of examples often matter most, so choose them carefully.
More in Prompt Engineering
Key facts
- The 2020 GPT-3 paper by Brown and colleagues popularized few-shot prompting, showing that a large model can learn a task from a few examples placed in its input with no weight updates.1
- Min and colleagues found in 2022 that the format and label space of examples can matter more than whether the labels in the examples are correct.2
- Few-shot performance has been shown to vary with the order and choice of examples, in some cases swinging from near chance to near state of the art.3
Related concepts
Quick checkWhat is few-shot prompting?Show answer
It is including a small number of worked examples in the prompt so that a language model can infer the task pattern and apply it to a new input without any retraining.
Sources
- Brown et al., Language Models are Few-Shot Learners, https://arxiv.org/abs/2005.14165
- Min et al., Rethinking the Role of Demonstrations: What Makes In-Context Learning Work?, https://arxiv.org/abs/2202.12837
- Lu et al., Fantastically Ordered Prompts and Where to Find Them, https://arxiv.org/abs/2104.08786
Editorially reviewed by Specialty Digest Editorial TeamLast reviewed November 17, 2026Researched and drafted with AI assistanceReport an issue
