Few-Shot Examples
Show, don't tell
A few worked examples in the prompt teach format, tone and edge-case behavior far better than prose. Standouts: quality examples beat quantity, and bad examples are contagious.
What you will learn
- Select high-quality, representative examples
- Cover realistic edge cases explicitly
- Measure example-set changes
What is this?
Few-shot prompting puts a handful of (input, ideal output) pairs before the task. The model generalizes style, structure and edge behavior from the examples better than from adjectives. The catch: models copy whatever they see — a poor example is contagious and will reproduce its flaw.
Why do you need it?
- A concrete example communicates intent better than a paragraph (usually).
- Edge-case examples teach the model what to do when input is unusual.
- Format/JSON-style examples lock structure reliably.
- Cost is fixed and small: 2-8 examples typically suffice.
Mental model
Learning how to write by imitating model letters
Few-shot examples
Showing a learner three perfect letters teaches shape, stroke order and spacing better than a rulebook. But a single sloppy letter in the examples will be copied faithfully — learners imitate examples, for better and worse.
How it works
- Choose 2-8 examples covering: common case, tricky boundary, failure to avoid.
- Vary topics so the model learns the TASK, not the topic (avoid topic overfitting).
- Match the target format exactly in every example.
- Put examples between instructions and the real query.
- Regenerate examples whenever the desired behavior changes.
Prompt anatomy with examples.
In production
- Classification prompts use label-balanced examples to fix skew.
- Formatting tasks use JSON examples to eliminate parse errors.
- Support copilots show one 'never make promises' example.
Best practices
- Audit every example as if it were production output.
- Keep example set small (2-8) unless measurement says otherwise.
- Match examples to the REAL data distribution, not idealized inputs.
- Store examples beside the prompt, versioned.
Common mistakes
- Loading the prompt with dozens of one-off examples.
- Examples that mismatch the desired output format.
- Forgetting adversarial examples that teach failure heuristics.
Common issues
Outputs mirror the example's topicExamples too topical or few
Broaden topics; make examples use varied entities.
Examples too long for costingVerbose exemplars per call
Shorten examples; trim to the essential contrastive pair.
Debugging tips
- Model copies an example's style into bad output → that example is teaching wrong behavior; replace.
- Format degradation on edge cases → add a dedicated edge-case example.
- Topic-overfit answers → diversify example topics so task-generalization dominates.
Interview checkpoint
Hands-on lab
- Create a labeled example table for a sentiment task
- Replicate few-shot behavior with a nearest-example fallback
- Assemble a k-shot prompt and measure its token size
Few-Shot Classification, No API
25 min · beginner
Quick quiz
Frequent few-shot failure mode to avoid:
The model can learn unwanted behavior from a single bad example.