BroadRouter

Few-shot prompting

Updated

Few-shot prompting is a technique in which a prompt includes a small number of worked input-output examples before the real input, so a language model infers the task and format from them. The model's weights do not change; zero-shot uses no examples and one-shot uses one.

Also called: few-shot learning, multishot prompting, in-context examples, one-shot prompting

Showing beats telling. A few examples often fix format and tone faster than a paragraph of rules.

How it works

The GPT-3 paper by Brown and colleagues made the term common. It tested a 175-billion-parameter model with tasks “specified purely via text interaction with the model”, with no gradient updates or fine-tuning, and found that few-shot performance improved strongly with model size. The paper defines three settings:

Setting Examples in the prompt
Zero-shot none, only an instruction
One-shot one
Few-shot several, limited by the context window

A few-shot prompt for labelling support tickets might look like this:

Ticket: "My card was charged twice." -> billing
Ticket: "The app crashes on login." -> bug
Ticket: "Can you add dark mode?" -> feature_request
Ticket: "I was billed after cancelling." ->

The model continues the pattern. Anthropic’s guide calls examples “one of the most reliable ways to steer” format, tone and structure, and asks that they be relevant, diverse and wrapped in tags so the model can tell them apart from instructions.

Why it matters

  • Format control. Examples show edge cases that rules miss, such as how to write an empty field. For strict JSON, pair them with structured output.
  • Cost. Every example is resent as input on every call. Five 200-token examples add 1,000 tokens per request. Placed in a fixed prefix, they can be billed as cached input tokens.
  • Reasoning. Examples that show the steps, not just the answer, are chain-of-thought prompting.
  • When to stop. If you need hundreds of examples, fine-tuning may be cheaper per call than sending them every time.

On BroadNet Inference

Few-shot prompting needs no special API feature; it is plain text in messages. BroadNet reports cached_tokens in usage, so you can check whether your example block is being read from cache. On a PAYG key the cached price is lower than the input price; on DeepSeek V4.1 Flash that is $0.0055 against $0.175 per 1M tokens. For Arabic tasks, see Arabic prompt engineering, and for document extraction with examples, the Arabic invoices guide.

Common mistakes

  • Using examples that all share one label or length. The model copies the bias.
  • Rotating examples per request. It breaks the cached prefix and makes results harder to compare.

Questions

How many examples should a few-shot prompt have?

Anthropic suggests 3 to 5 for best results. More examples cost more input tokens on every call, so stop adding them once quality stops improving.

Is few-shot prompting the same as fine-tuning?

No. Few-shot examples live in the prompt and are resent on every request. Fine-tuning changes the model weights once, so the examples no longer need to be sent.

Should the examples go in the system prompt or as chat turns?

Either works. Keep them in a fixed position near the start so they form a stable, cacheable prefix.

Read as MarkdownAsk ChatGPTAsk ClaudeAsk Perplexity