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.

Related terms

  • In-Context Learning In-context learning is the ability of LLMs to learn new tasks from examples provided directly in the prompt, without updating model weights. By showing the model input-output pairs (few-shot examples), it generalises to new inputs in the same format.
  • Chain-of-Thought (CoT) Prompting Chain-of-Thought prompting elicits step-by-step reasoning from an LLM before it produces a final answer. By showing or requesting intermediate reasoning steps, CoT dramatically improves accuracy on arithmetic, logical reasoning, and multi-step problem-solving tasks.
  • LLM (Large Language Model) A Large Language Model is a neural network trained on massive text corpora to predict and generate text. LLMs like GPT-4, Claude, and Gemini exhibit broad language understanding, reasoning, and generation capabilities that emerge from scale.
  • Zero-Shot Prompting Zero-shot prompting asks an LLM to perform a task without providing any examples, relying entirely on the model's pre-trained knowledge and the clarity of the instruction. It works well for common tasks but often requires examples for specialised or nuanced outputs.