Few-shot prompting uses examples to teach LLMs new formats and behaviours without fine-tuning. This guide explains how to construct effective examples and when few-shot beats zero-shot.
Few-shot prompting includes 2–5 worked examples in the prompt before the actual question. The model learns the desired output format and style from the examples, then applies it to the new input. It is the fastest way to teach an LLM a new task without fine-tuning.
LLMs are excellent at pattern matching from context. A few well-chosen examples can specify complex output structures, tone, reasoning style, or domain-specific formatting that would be difficult to describe verbally.
Each example consists of an input followed by the desired output. Separate examples clearly — use consistent delimiters like 'Input:' and 'Output:', or XML tags like `<example>` / `</example>`. Consistency in formatting is more important than the specific delimiter choice.
After the examples, present the actual input with the same format but omit the output. The model will complete the pattern. End with 'Output:' (or your chosen label) to prime the generation.
Diversity matters more than quantity. Choose examples that cover different cases, different lengths, and different edge cases you expect in production. Two diverse examples usually outperform five similar ones.
Order the examples from simple to complex. The model applies the most recent examples most heavily, so put your most representative example last.
If your task involves specific formatting — tables, JSON, custom markup — show the exact format in the examples. The model will mirror it precisely.
Zero-shot (no examples) works for simple tasks with a large model. Few-shot is better when the output format is unusual, the domain is specialised, or zero-shot gives inconsistent results. Fine-tuning is only justified when you have 1000+ examples and need the lowest possible inference cost for a specific task.
Start with zero-shot. If the output is inconsistent, add 2 examples. If still inconsistent, add 3 more. If you are writing more than 5 examples for every prompt, consider fine-tuning instead.
The system prompt is the most powerful lever you have over LLM behaviour. This guide covers the key components of an effective system prompt, common mistakes, and battle-tested patterns for production use.
Read guideChain-of-thought (CoT) prompting dramatically improves LLM performance on multi-step reasoning tasks. This guide explains when and how to use it, from simple 'think step by step' to structured CoT templates.
Read guide