Few-Shot Prompting
Few-shot prompting means including a few examples of the task, input and desired output, inside the prompt. The model picks up the pattern from the examples, a behaviour often called in-context learning. One example is called one-shot.
A Few-Shot Example
Turn product features into short benefit statements.
Feature: 20-hour battery
Benefit: Go a full day and night without hunting for a charger.
Feature: Waterproof to 50m
Benefit: Swim, surf or get caught in the rain without worry.
Feature: Weighs 180g
Benefit:Sample response: Light enough to carry all day without noticing it's there.
The examples teach length, tone and structure far better than describing them would. The prompt ends right where the model should continue.
Few-Shot for Custom Labels
Classify support tickets as BILLING, BUG or FEATURE.
Ticket: "I was charged twice this month." -> BILLING
Ticket: "The export button does nothing on Safari." -> BUG
Ticket: "Could you add dark mode?" -> FEATURE
Ticket: "My invoice shows the wrong company name." ->Sample response: BILLING
Choosing Good Examples
- Cover each label or case at least once.
- Make examples varied so the model learns the rule, not a surface pattern.
- Keep them consistent in format; the model copies inconsistencies too.
- Include a tricky edge case if one matters.
- 2-5 examples is usually enough; more costs tokens with diminishing returns.
Common Mistakes
- All examples have the same label, so the model always picks it.
- Examples are much shorter or longer than real inputs.
- Example outputs contain errors the model will imitate.
- Order bias: the last example has extra influence; shuffle or balance them.
Few-Shot in Chat Format
With chat APIs you can provide examples as previous user/assistant turns:
[
{"role": "system", "content": "Reply with the capital city only."},
{"role": "user", "content": "France"},
{"role": "assistant", "content": "Paris"},
{"role": "user", "content": "Kenya"}
]Sample response: Nairobi
Frequently asked questions
How many examples should a few-shot prompt have?
Usually two to five. Test with more only if quality keeps improving.
What is in-context learning?
The ability of an LLM to pick up a task from examples in the prompt, without retraining the model.
Is few-shot prompting the same as fine-tuning?
No. Few-shot puts examples in each prompt; fine-tuning changes the model weights using many examples.