Few-Shot Prompting
Learning from in-context examples
Few-shot prompting provides examples of input-output pairs before the actual query. The model infers the task pattern from the demonstrations rather than from an explicit instruction. Example selection, ordering, and format have a measurable impact on accuracy.
Few-shot prompting exploits a remarkable property of large language models: given a handful of input-output examples, they can infer the underlying task and apply it to a new input — without any parameter updates. This is in-context learning. For tasks where describing the rules in words is hard but showing examples is easy (style transfer, label taxonomies, domain-specific formatting), few-shot prompting often outperforms zero-shot.
Three factors dominate few-shot performance. First, example selection: examples should cover the diversity of expected inputs and include edge cases. If your classification task has five labels, include at least one example per label. Second, ordering: models are sensitive to recency — the last example disproportionately influences the output. Place the most representative example last. Third, format consistency: every example must follow an identical template (same delimiters, same label format, same level of detail). Inconsistent formatting teaches the model noise rather than signal.
The number of examples is a tradeoff between quality and token cost. For most tasks, 3–5 well-chosen examples provide most of the benefit. Beyond 8–10, returns diminish and the prompt becomes expensive. A powerful hybrid approach is to combine a brief zero-shot instruction with a few examples: the instruction frames the task while the examples demonstrate the expected format and edge cases. This combines the clarity of instruction-following with the precision of demonstration-based learning.
Key Concepts
- Few-shot prompting provides input-output examples so the model infers the task implicitly
- Example selection: cover label diversity and include edge cases
- Ordering matters: the last example disproportionately influences the output
- Format consistency across all examples is critical — inconsistency teaches noise
- 3–5 well-chosen examples capture most benefit; combine with a brief instruction for best results