Few-Shot Prompting: Guide With Examples

4 min read

Few-shot prompting means including a handful of examples (typically 2-5) in your prompt so the model can learn the pattern you want.

The Pattern

Classify the topic of each headline:

Headline: "Fed Raises Interest Rates by 0.25%"
Topic: Economics

Headline: "New Species of Deep-Sea Fish Discovered"
Topic: Science

Headline: "Lakers Win Championship in Overtime Thriller"
Topic: Sports

Headline: "SpaceX Launches New Satellite Constellation"
Topic:  ← the model completes this

The model sees the pattern from your examples and fills in: Science (or Technology — both reasonable).

Why It Works

Examples do three things:

  1. Define the task — the model infers what you want from the pattern
  2. Set the format — consistent input/output structure gets replicated
  3. Calibrate the output — examples show the expected length, tone, and style

Tips for Better Few-Shot Prompts

  • Diverse examples: Cover edge cases, not just easy ones
  • Consistent format: Use the same structure for every example
  • Show what to do: Positive examples (“do it like this”) teach patterns more effectively than anti-patterns (“don’t do this”)
  • Separate examples from instructions: Use clear delimiters or tags (e.g. <example>) so the model doesn’t confuse your examples with the actual task input
  • Order matters: Models tend to weigh later examples more heavily, so put your most representative example last — closest to the actual query
  • Quality over quantity: 3 great examples beat 10 mediocre ones

Few-Shot vs Zero-Shot: When to Use Which

Not sure whether to include examples? Here’s a quick rule of thumb:

  • Use zero-shot when the task is simple and well-defined (e.g., “translate this to French,” “summarize this paragraph”)
  • Use few-shot when you need the model to match a specific format, tone, or pattern — or when zero-shot gives inconsistent results
  • One-shot (a single example) can work when one example is enough to show the pattern — it’s just few-shot with fewer examples

When even examples aren’t enough, the next technique — system prompts — lets you set persistent rules for the entire conversation.

Quick Quiz

Question 1 of 2

How many examples typically make a prompt "few-shot"?