Few-Shot Prompting Guide: Teach Any LLM a New Task With a Handful of Examples

Few-Shot Prompting Guide: Teach Any LLM a New Task With a Handful of Examples

This few-shot prompting guide explains how to teach a language model a new task by showing it a handful of examples instead of training it. You put two, five or ten input-and-output pairs in the prompt, and the model infers the pattern and applies it to your real input. The central question is how many examples you need and how to choose them, and the short answer is that three to eight well-chosen examples beat twenty random ones, because quality and diversity matter far more than quantity.

Few-shot prompting is the oldest prompting technique in the modern era, and it is still the most useful. It needs no labelled dataset, no training run and no deployment pipeline, which makes it the fastest way to test whether a model can do a job at all.

Key takeaways

  • Few-shot prompting teaches a task through examples in the prompt, with no training or gradient updates.
  • GPT-3 showed in 2020 that a 175-billion-parameter model could match fine-tuned models on many tasks using only a few examples.
  • Three to eight diverse, representative examples usually beat a large set of similar ones.
  • Example order, format consistency and label balance all change results, so test them deliberately.
  • Use few-shot prompting as the first test of a task, and move to fine-tuning only when prompting cannot reach the quality bar.

What few-shot prompting is

Few-shot prompting means including a small number of completed examples in the prompt before the real input. Each example shows the model an input and the desired output, in the same format the model should produce.

The model does not learn in the usual sense: no weights change. Instead it recognises the pattern from the examples and continues it, a process researchers call in-context learning.

The technique sits between two simpler approaches. Zero-shot prompting gives the model an instruction and no examples, which works when the task is obvious or familiar.

One-shot prompting gives a single example, which is enough to fix the format but rarely enough to teach a subtle pattern. Few-shot prompting gives enough examples to show the rule, including its edge cases, without turning the prompt into a dataset.

Each step up costs context. Every example consumes tokens that could have gone to the real input or to a longer answer, and every example adds latency. The skill of few-shot prompting is getting the most pattern per token: the smallest set of examples that still teaches the rule. Best for: classification, extraction, formatting and any task where the output pattern is easier to show than to describe.

The evidence: GPT-3 and in-context learning

Few-shot prompting entered the mainstream with GPT-3, described by Brown and colleagues in the 2020 paper “Language Models are Few-Shot Learners”, presented at NeurIPS 2020. The team trained a 175-billion-parameter autoregressive language model and tested it in the few-shot setting, with tasks and demonstrations specified purely through text. No gradient updates, no fine-tuning: the model was applied to translation, question answering, cloze tasks and on-the-fly reasoning using only examples in the prompt.

The results were a surprise. On many benchmarks, few-shot GPT-3 was competitive with prior state-of-the-art fine-tuning approaches, despite never being trained on the task.

The paper also found a clear scaling pattern: while zero-shot performance improved steadily with model size, few-shot performance increased more rapidly, which showed that larger models are more proficient at in-context learning. Bigger models do not just know more; they learn more from the examples you give them.

That finding still shapes practice. Few-shot prompting works best on capable models, and its value grows with model size.

On a small model, three examples may teach nothing; on a large one, they can replace a training set. The original paper is available on arXiv at arXiv:2005.14165. Best for: teams with access to a capable model who want to ship a new capability without a training pipeline.

How many examples do you need?

Start with three to five, and add more only when measurement shows a gain. The first examples teach the format and the basic rule; the next few teach the edge cases. Beyond eight or ten, the returns usually flatten, and the costs keep rising: context consumed, latency added, and the risk that the model starts copying the examples instead of generalising from them.

There are exceptions. A task with many output classes may need one example per class, so a ten-way classifier may need ten or more.

A task with rare edge cases may need an example for each case. But the default should be restraint: a prompt with five examples that scores 92% is better than a prompt with twenty that scores 93%, because the shorter prompt is cheaper, faster and easier to maintain.

Measure the trade-off directly. Build a small test set of fifty to a hundred real inputs, run the prompt with three, five and ten examples, and plot accuracy against token cost. The curve usually bends sharply after the first few examples, and the bend tells you where to stop. Best for: any task where you can build a small test set and let the numbers decide the example count.

Choosing examples that actually teach

Choose examples for diversity, not for ease. A set of five examples that all look the same teaches the model one case five times.

A set that covers the main variations, the common edge cases and one genuinely hard case teaches the rule. Include the cases your users actually send, not the clean cases you wish they sent.

Balance the labels. If four of your five examples are positive and one is negative, the model will lean positive, because it infers the base rate from your examples.

The same applies to output styles: if every example is short, the model will answer short. Deliberately include the minority classes and the longer outputs, even if they are less common in real traffic.

Use real data where you can. Examples written from imagination tend to be cleaner and more regular than real inputs, and the model learns the regularity instead of the rule. Pull examples from actual logs, anonymised where needed, and keep them current: a prompt whose examples describe last year’s product will teach last year’s behaviour. Best for: tasks where the input distribution is messy, skewed or hard to describe in words.

Format, order and the traps that change results

Format consistency is the cheapest win in few-shot prompting. Use the same separators, the same labels and the same line breaks in every example, and use the same format for the real input.

A model that sees “Input:” and “Output:” five times will continue the pattern; a model that sees three different separators will guess. Put the instruction first, then the examples, then the real input, and keep the final input in exactly the same shape as the examples.

Example order matters more than most people expect. Models show a recency bias: they weight the last examples more heavily, and they can be swayed by a single unusual example placed at the end.

If your results swing when you shuffle the examples, that is a signal the prompt is fragile. Shuffle deliberately during testing, and prefer the ordering that is most stable, not the one that scores highest on a single run.

Watch for leakage. An example that is too similar to a test input can make your evaluation look better than it is, and an example that contains the answer to a common query can teach the model to parrot rather than reason. Keep your test set separate from your examples, and re-check the prompt whenever the examples change. Best for: production prompts where stability across runs matters as much as peak accuracy.

Comparing few-shot prompting with the alternatives

Approach Setup effort Cost per call Best accuracy When to use it
Zero-shot Low, instruction only Lowest Good on familiar tasks Simple, well-known tasks
One-shot Low, one example Low Good for format fixing When only the format is unclear
Few-shot Medium, 3 to 8 examples Medium High on most tasks New tasks with a clear pattern
Many-shot High, dozens of examples High Highest on hard tasks Complex rules, long-context models
Fine-tuning Highest, dataset and training Lowest per call Highest overall High volume, stable tasks

The table shows few-shot prompting as the middle path: more capable than zero-shot, far cheaper to set up than fine-tuning. Many-shot prompting, with dozens or hundreds of examples, can beat few-shot on hard tasks, but only on models with long context windows, and the token cost is hard to justify at scale. Fine-tuning wins on accuracy and per-call cost, but only after you have a dataset and a training pipeline, which is exactly what few-shot prompting lets you avoid.

A teacher showing a student three worked examples on a whiteboard before the student tries a new problem alone
Three good examples teach a pattern better than twenty similar ones, whether the learner is a student or a language model.

Few-shot prompting versus fine-tuning

The real decision is not how many examples to use, but whether to prompt or to fine-tune. Few-shot prompting wins on speed: you can test a task in an afternoon, change the behaviour by editing text, and roll back by reverting a file. Fine-tuning wins on cost at scale and on reliability: once trained, the model needs no examples in the prompt, so every call is shorter and cheaper, and the behaviour is baked in rather than inferred.

Use few-shot prompting first, always. It tells you whether the task is solvable, what good output looks like, and which examples matter.

Those answers become the training data if you later fine-tune, so the prompting work is never wasted. Move to fine-tuning when the volume is high, the task is stable, and the prompt has grown so long that example tokens cost more than a training run would save.

For the decision criteria in full, including the cost crossover point, see our guide to fine-tuning versus prompt engineering. It covers when each approach wins and how to calculate the break-even volume. Best for: teams deciding between a prompt they can ship today and a model they can ship next month.

Few-shot prompting checklist

  • Three to eight examples, chosen for diversity and edge cases, not for ease.
  • Labels balanced across classes, including the minority classes.
  • Identical format in every example and in the real input, with the same separators and labels.
  • Examples drawn from real inputs, anonymised where needed, and kept current.
  • Example order shuffled during testing, with the most stable ordering kept.
  • Test set kept separate from examples, with accuracy measured per example count.
  • A written decision on when to move to fine-tuning, based on volume and cost.

Frequently asked questions

What is few-shot prompting?

It is a technique where a handful of input-and-output examples are included in the prompt, so the model infers the pattern and applies it to a new input. No training or weight updates are involved; the learning happens inside the prompt.

How is few-shot prompting different from zero-shot prompting?

Zero-shot prompting gives the model an instruction and no examples, while few-shot prompting adds examples that demonstrate the task. Few-shot is more accurate on new or unusual tasks, but it costs more tokens per call.

How many examples should I use?

Three to eight is the usual range. Start with three to five, measure accuracy on a test set, and add more only while accuracy keeps improving. Beyond ten, the gains usually flatten while the token cost keeps rising.

Does example order really matter?

Yes. Models weight recent examples more heavily, so a single unusual example at the end can skew results. Shuffle the examples during testing and keep the ordering that is most stable across runs.

When should I stop prompting and fine-tune instead?

Fine-tune when the task is stable, the volume is high, and the prompt has grown long enough that example tokens cost more than a training run would save. Few-shot prompting remains the right first step either way. For the operational side, see our guide to LLM prompt management systems.

Latest articles

Scroll to Top