Prompt technique
Few-Shot Prompting
Show the model a handful of input/output pairs and it will mimic the pattern.
What it is
Few-shot prompting (also called in-context learning) gives the model 2–8 demonstrations of the task before asking it to perform on a new input. The model picks up format, tone, vocabulary and edge cases from the examples without any fine-tuning. This is the highest-leverage technique for structured output, custom formats, and domain-specific tone.
When to use it
- ✓You need a specific output format (JSON shape, table, custom DSL)
- ✓Tone, voice or vocabulary that the model wouldn't pick by default
- ✓Classification or extraction tasks with subtle label boundaries
Example
Classify the sentiment of each review as POSITIVE, NEGATIVE, or MIXED.
Review: "The screen is gorgeous but the battery dies in 3 hours."
Label: MIXED
Review: "Best laptop I've ever owned, no complaints."
Label: POSITIVE
Review: "{user_review}"
Label:Why it works: Two demonstrations anchor the label set and the boundary case (MIXED) before the model is asked to classify a new review.
Pitfalls
- !Biased examples bias the output — pick demonstrations that span the full label distribution.
- !Token cost grows with the prompt; cache the few-shot block when possible.