Glossary/F/few-shot prompting
Prompting Also called: few-shot learning, in-context learning, multishot prompting, one-shot prompting, n-shot prompting

What is few-shot prompting?

Few-shot prompting is putting a handful of worked examples in the prompt so the model treats them as the pattern to follow on the next input. The examples show input and desired output, sit before the real query, and change the reply without any weight update. The GPT-3 paper introduced the label to describe how a fixed model can be steered by demonstrations at inference time, in contrast to zero-shot (no examples) and fine-tuning (weights actually change).

What is few-shot prompting and what changes in your prompt?

The mechanism is plain. You write two to a dozen worked examples above the real question and the model completes the pattern. Nothing about the model changes, because there is no training run, no adapter and no gradient. What changes is the distribution the next token is sampled from, because the examples now dominate the visible prompt and the model has been trained on data where a series of paired questions and answers is followed by another answer in the same shape.

The GPT-3 paper gave the technique its name and its taxonomy. Zero-shot is a task description with no examples, one-shot is a task description plus one example, few-shot is a task description plus several examples. Anthropic uses multishot for the same idea when it wants to fold one-shot into the label. All three run at inference time, all three cost only prompt tokens, and all three leave the model file untouched.

How is few-shot prompting different from fine-tuning?

Fine-tuning writes new weights. Few-shot prompting resends examples on every call. The consequences differ in every direction that matters to a shipping system.

  • Cost per call. Few-shot pays for the example tokens on every request; fine-tuning pays once for the training job and then bills at the base per-token rate.
  • Iteration speed. Editing a few-shot prompt is a text change. Editing a fine-tuned model is a new training run and a redeploy.
  • What travels. A few-shot prompt is portable across providers and base models. A fine-tuned model is tied to the provider and base checkpoint you trained on.
  • Where the behaviour lives. Few-shot behaviour is visible in the prompt, so a reviewer can read it. Fine-tuned behaviour is baked into weights and is only visible through evals.

The rule of thumb from every provider guide is to start with prompting, add examples when instructions alone are ambiguous, and reach for fine-tuning only when the prompt is long, hot and stable enough that paying the training cost beats paying the token cost of the examples on every call.

How many examples, and where do they go?

Anthropic's guidance is three to five diverse examples for most cases, with the caveat that quality and coverage matter more than count. The examples should include the edge cases you care about, use the same input format your production traffic uses, and show the exact output shape you want back. OpenAI's prompt engineering guide gives the same shape of advice and adds one concrete tip: use a stable delimiter to separate the demonstrations from the real query, so the model can tell where the examples end.

Placement matters because attention is not uniform across a long input. Put the examples close to the instruction and the real query at the end. If you are also carrying a system prompt and a tool schema, remember they share the same context window: a bank of twenty examples can push the system prompt out of the model's attention before the reply even starts.

Where few-shot prompting quietly breaks

Three failure modes come up often enough to plan for. The first is example bias: whatever pattern sits in your examples is the pattern the model copies, including biases you did not notice. If all five examples answer in one sentence, a case that needs three sentences gets one sentence. If every example uses one label from a set of ten, the other nine labels get picked less often at inference.

The second is contamination between examples and the query. If your examples happen to include text that resembles the real input, the model can answer from the demonstration instead of reading the query. This is easy to trigger with retrieval systems that draft examples from the same corpus the question came from.

The third is silent drift when you swap the model. Few-shot behaviour depends on how the model was trained to attend to demonstrations, and that changes across families and versions. When you upgrade the model, re-run your eval before you assume the same examples still work.

A three-shot classification prompt sent to a Messages endpoint

POST /v1/messages
{
  "model": "claude-sonnet-4-5",
  "max_tokens": 32,
  "system": "You label support tickets. Reply with one label from the set: billing, auth, shipping, other.",
  "messages": [
    {"role": "user",      "content": "Ticket: 'my card was charged twice this month'"},
    {"role": "assistant", "content": "billing"},
    {"role": "user",      "content": "Ticket: 'the reset email never arrived'"},
    {"role": "assistant", "content": "auth"},
    {"role": "user",      "content": "Ticket: 'parcel says delivered but I never got it'"},
    {"role": "assistant", "content": "shipping"},
    {"role": "user",      "content": "Ticket: 'how do I change the address on my invoice?'"}
  ]
}

response.content[0].text:
"billing"

The three prior turns are the shots. They fix the label set, the reply length and the tone. Every request resends all three, so the shot tokens are billed on every call until you cache the prefix or move the behaviour into a fine-tune.

Common questions

Few-shot prompting: frequently asked

Is in-context learning the same as few-shot prompting?

They overlap. In-context learning is the general phenomenon that a fixed model can pick up a task from patterns in its prompt, and few-shot prompting is one way to invoke it by supplying worked examples. Zero-shot instructions and one-shot demonstrations are also in-context learning. In casual writing the two labels are used as synonyms, which is fine as long as you know few-shot specifically means several examples.

How many examples should I include?

Anthropic suggests three to five as a starting point and notes that diversity matters more than count. OpenAI's guide gives similar advice. Add examples one at a time and stop when the eval score stops moving, because every extra example adds tokens on every call and can pull the model toward whatever bias the extras carry.

When is fine-tuning cheaper than few-shot prompting?

When the example bank is long, the traffic is high and the behaviour is stable. A prompt with 2,000 tokens of examples costs those 2,000 tokens on every request, so at millions of calls the recurring bill exceeds the one-time training cost. If the examples change weekly, prompting stays cheaper because you skip the retraining; if they have not moved in months, fine-tuning is worth pricing.

Does prompt caching help with long few-shot prompts?

Yes, when the examples sit at the start of the prompt and do not change between calls. Providers hash a prefix once and read it back at a lower rate on subsequent requests, which is exactly the shape of a shared example bank followed by a varying query. See prompt caching for the per-provider numbers.

Sources

Where these facts come from