Why does the ORDER of few-shot examples in a prompt measurably affect output quality and where should the most-representative example go?
LLMs are recency-biased; the example nearest the query has the strongest priming effect, so put the most-representative example last and avoid style oscillation across examples.
Imagine you are about to imitate someone's drawing style. Someone shows you five sketches, then says: 'now you draw.' The sketch you saw most recently is the one most fresh in your mind, so it will shape your strokes the most. If they show you a cartoon, then a realistic portrait, then a cartoon, you will probably mash styles together. Few-shot examples work the same way: the model is about to draw right after the last example, so put the cleanest one closest to the prompt, and do not zig-zag between styles.
Detailed answer & concept explanation~4 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
3 min: recency bias mechanism + canonical example last rule + style oscillation failure + measured effect size + interaction with long context and retrieval.
Real products, models, and research that use this idea.
- Anthropic's prompt engineering guide explicitly recommends placing the strongest example last for Claude Opus 4.7 and Sonnet 4.x few-shot prompts.
- DSPy automatically reorders selected demonstrations by similarity to the query, with most-similar last, when compiling prompts.
- OpenAI cookbook examples for few-shot classification show the canonical (input, output) pair as the final demonstration for the same reason.
- LangChain's `FewShotPromptTemplate` exposes an `example_selector` slot that ranks examples; teams pair it with similarity-based selection putting the closest match last.
What an interviewer would ask next. Try answering before peeking at the approach.
QDoes the recency bias rule still apply when the prompt is 32k tokens long and examples span the middle?
QIf you have ten examples but the model context can only fit four, how do you pick and order them?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Treating the example list as a set rather than a sequence. The model reads it left to right and the last example is right next to where it starts generating; that position matters.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.