How do you select and order few-shot examples? What are the known pitfalls?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Selection principles:
- Cover the input distribution - examples should span the real variety of inputs (lengths, formats, topics), not five paraphrases of the easy case. Include the edge cases you actually care about: the empty input, the ambiguous case, the adversarial one.
- Include hard cases near the decision boundary - for classification, borderline examples define the boundary; obvious examples teach nothing the instruction didn't.
- Balance labels - models exhibit majority label bias: if 4 of 5 examples are "positive," predictions skew positive regardless of input. Keep the demonstrated label distribution roughly uniform (or matched to a known prior, deliberately).
- Keep them correct and consistent - examples override written instructions when they conflict. An example whose output violates your stated format wins, and now your format is broken.
Full worked answer
Selection principles:
- Cover the input distribution - examples should span the real variety of inputs (lengths, formats, topics), not five paraphrases of the easy case. Include the edge cases you actually care about: the empty input, the ambiguous case, the adversarial one.
- Include hard cases near the decision boundary - for classification, borderline examples define the boundary; obvious examples teach nothing the instruction didn't.
- Balance labels - models exhibit majority label bias: if 4 of 5 examples are "positive," predictions skew positive regardless of input. Keep the demonstrated label distribution roughly uniform (or matched to a known prior, deliberately).
- Keep them correct and consistent - examples override written instructions when they conflict. An example whose output violates your stated format wins, and now your format is broken.
Ordering pitfalls: few-shot performance is disturbingly sensitive to permutation - Lu et al. (Fantastically Ordered Prompts and Where to Find Them) showed the same examples in different orders swing accuracy from near-SOTA to near-random on some tasks. The dominant effect is recency bias: the last example exerts the strongest pull on the prediction. Zhao et al. (Calibrate Before Use) systematised this - majority label bias, recency bias, and common-token bias - and showed you can partially correct with output calibration (fit an affine correction using a content-free input like "N/A"). Practical hygiene: don't end on an example whose label you want to avoid over-predicting; if you can't eval orderings, alternate labels and put a representative (not extreme) example last.
Beyond static sets: dynamic few-shot retrieves the k nearest labelled examples per request (kNN over embeddings). It usually improves accuracy on diverse inputs but breaks prompt-cache prefix sharing and adds a retrieval dependency - a real tradeoff worth naming.
Also know Min et al. (2022): randomising the labels in demonstrations often barely hurts - much of few-shot's value is conveying format, input distribution, and label space rather than the input→label mapping itself. That's why format-perfect examples matter so much.
What a good answer covers
- Cover the input distribution - examples should span the real variety of inputs (lengths, formats,…
- Include hard cases near the decision boundary - for classification, borderline examples define the…
- Balance labels - models exhibit majority label bias
- Keep them correct and consistent - examples override written instructions when they conflict
- Ordering pitfalls: few-shot performance is disturbingly sensitive to permutation - Lu et al
Key terms: Cover the input distribution · Balance labels · Keep them correct and consistent · recency bias · dynamic few-shot
In the glossary: Few-shot · Accuracy · Calibration
Interviewer follow-ups to expect
Your 5-shot classifier over-predicts one class - what do you check first?
When is it deliberately correct to match example label distribution to a skewed real-world prior?
How would you test ordering sensitivity cheaply?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep