AI glossary · Models and context
What is few-shot prompting?
Also called: multishot prompting, in-context examples, k-shot prompting
Definition
Few-shot prompting is giving a model a handful of worked input-and-output examples, typically two to five, inside the prompt so it copies the pattern for a new input without retraining.
Explained
How does few-shot prompting work?
A “shot” is an example. Zero-shot gives only the instruction, one-shot adds a single example, and few-shot adds several. The examples cost input tokens on every request, so they are worth adding only where instructions alone drift.
The model reads the examples as part of its context window and infers the format, labels and tone from them, which is why the technique is also called in-context learning. Nothing about the model changes: remove the examples and the behaviour goes with them. The prompt builder has a slot for examples.
OpenAI’s 2020 GPT-3 paper, “Language Models are Few-Shot Learners”, showed a 175-billion-parameter model handling translation, question answering and 3-digit arithmetic from demonstrations given purely as text, with no gradient updates or fine-tuning.
Current advice: Anthropic suggests 3 to 5 relevant, varied examples wrapped in <example> tags. For reasoning models, OpenAI says to try zero-shot first and add examples only if needed, keeping them closely aligned with your instructions.
Example
Three examples for a ticket classifier
The zero-shot version of this prompt is 44 tokens with OpenAI’s o200k_base tokenizer. Adding the three labelled examples below makes it 90, 46 more per request. On GPT-6 Luna at $0.10 per million input tokens, that is $4.60 for every 1,000,000 requests.
That is cheap insurance for a classifier that might otherwise invent labels or explain itself. Examples get expensive when they are long, such as whole documents or code files sent on every call. Keep them unchanged at the start of the prompt so prompt caching can reuse them once the prefix is long enough.
Classify the customer message as one of: billing, delivery, product, other. Reply with the label only.
Message: I was charged twice for the same order.
Label: billing
Message: The left brake lever snapped after two rides.
Label: product
Message: Can I change the delivery address on my order?
Label: delivery
Message: My parcel was meant to arrive on Tuesday and there is still no sign of it.
Label:Cost and quality
Why use few-shot prompting?
Examples are often the quickest fix for format and label drift, and they show edge cases better than a paragraph of rules. Anthropic calls them one of the most reliable ways to steer output format, tone and structure.
But the model copies everything, including accidents: three examples with short answers teach short answers. Vary them deliberately, and compare results with and without them on your own test set rather than assuming they help.
Don’t mix up
Few-shot vs zero-shot prompting: what’s the difference?
- Few-shot vs zero-shot prompting
- Zero-shot relies on the instruction alone and is cheaper per request. Few-shot adds demonstrations, which usually make labels and format more consistent. Start zero-shot and add examples only for the cases where results drift.
- Few-shot prompting vs fine-tuning
- Few-shot examples live in the prompt and are paid for on every request. Fine-tuning trains them into the model’s weights once, so they no longer need sending, at the cost of a training job and a custom model.
- Few-shot vs chain-of-thought
- Plain few-shot examples show the answer. Chain-of-thought examples also show the working; the original chain-of-thought paper used few-shot examples that included reasoning steps.
FAQ
Questions people ask
What are zero-shot, one-shot and few-shot prompting?
They are named by the number of worked examples in the prompt. Zero-shot gives only an instruction, one-shot adds a single example, and few-shot adds several, usually two to five. More examples tend to make output format and labels more consistent, but each one adds input tokens to every request, so the cheapest version that works is the one to keep.
How many examples should a few-shot prompt have?
Two to five is the usual range, and Anthropic suggests three to five relevant, varied examples. Beyond a handful, each extra example adds cost on every request while the gain is often small, so measure on your own test set. Pick examples that represent real inputs, including an edge case, and keep them in a stable prompt prefix so prompt caching can discount them.
Go deeper
Try it and read more
- Free toolPrompt BuilderBuild prompts with variables and a live token count.
- Free toolPrompt Template LibraryPrompt templates for code review, tests, docs, SQL, RAG and LLM evals.
- Free toolAI Token CounterCount tokens for GPT, Claude, Gemini, DeepSeek, Qwen and more.
- Guide · 12 min readHow to calculate LLM API costs: the formula, worked examples and the trapsHow to calculate LLM API cost per request and per month: the token formula, worked examples for chatbots, RAG and agents, plus caching, batch and reasoning.
Related