Few-Shot Prompting
Few-shot prompting is a technique where you include a small number of example input-output pairs in your prompt to guide an LLM's response format and style. It's one of the most effective prompt engineering techniques for improving output quality without fine-tuning.
What is Few-Shot Prompting?
Few-shot prompting is the practice of including example demonstrations in your prompt to show the model exactly what output format, tone, or reasoning pattern you want. It is the most reliable tool in the prompt engineer's toolkit for steering model behaviour.
Structure of a Few-Shot Prompt
System: You are a sentiment classifier. Classify each review as Positive, Negative, or Neutral.
User: Review: "I love this product!" → Sentiment: Positive
Review: "Terrible quality, broke after a week." → Sentiment: Negative
Review: "It arrived on time." → Sentiment: Neutral
Review: "Best purchase I've made this year!" → Sentiment:
When to Use Few-Shot
- When the output format is specific and hard to describe verbally.
- When you need consistent structured output (JSON, tables, code).
- When zero-shot performance is insufficient.
- When fine-tuning is not available or practical.
Example Selection Strategies
- Random selection — Quick but inconsistent.
- Similarity-based — Retrieve the most similar examples to each query (few-shot RAG). Most effective.
- Diversity-based — Maximise coverage of different cases.
Chain-of-Thought (CoT) Few-Shot
One of the most powerful techniques: include examples that show reasoning steps, not just input-output pairs. This significantly improves performance on arithmetic, logic, and multi-step reasoning tasks.
Example
Instead of prompting 'Extract the date from this text', you provide 3 examples: ('Meeting on Jan 5' → '2026-01-05'), then ask the model to extract from a new text. The examples define the expected output format precisely.