Few-shot prompting
Few-shot prompting provides the model with example input-output pairs in the prompt to demonstrate the desired pattern before asking it to handle the actual input. 'Here are 3 examples of how to classify emails... now classify this one'. Few-shot consistently outperforms zero-shot on tasks with structured output or unusual format requirements.
Few-shot exploits the LLM's pattern-matching capability without requiring fine-tuning. The trade-off is context cost (examples take tokens) and the risk that the model overfits to surface patterns in the examples rather than the underlying intent. Production guidance: 3-5 examples is usually the sweet spot; examples should cover the variety of cases (not all easy or all hard); the order matters (recent examples weight more); and the format should match exactly the expected output. For genuinely novel tasks, few-shot can move accuracy from 40% to 85% without any model change.
Related terms
- System prompt
A system prompt is the initial instruction given to an LLM at the start of a session that sets behaviour, persona, output format, and constraints — distinct from user messages that follow.
- Chain-of-thought (CoT)
Chain-of-thought prompting asks the LLM to reason step by step before producing the final answer — 'let's think through this carefully' or 'show your work'.
- Structured output
Structured output is the LLM feature that guarantees the response matches a provided schema (JSON Schema, Zod, Pydantic) — eliminating the parsing failures and format drift that plagued early LLM applications.