Few-Shot Prompting

What Is Few-Shot Prompting?

Few-shot prompting is the technique of providing a small number of input-output examples in the prompt before asking the model to perform the actual task. The examples demonstrate the pattern you want. The model generalizes from them.

The Terminology

The terms come from machine learning research. Zero-shot means no examples — you ask directly. One-shot means one example. Few-shot means a small number — typically 2 to 5. The number reflects how many demonstrations you provide before the actual task.

Why Examples Work

LLMs are trained to continue patterns. When you show the model a sequence of input-output pairs, you are establishing a pattern in the context that the model is strongly motivated to continue.

Describing the output

"Classify each review as positive or negative. Return only the label."

This description is clear — but the model may still vary the format: "Positive", "The sentiment is positive", "POSITIVE".

Showing the output

Review: "Works great!" → Positive
Review: "Broken on arrival." → Negative
Review: "Fine, nothing special." → Neutral

The format is now unambiguous. The model sees the exact label style and follows it consistently.

Demonstration Beats Description

A description can be interpreted in multiple ways. An example is unambiguous. The example shows the exact output format, vocabulary, and structure without requiring any of it to be described in words.

Writing Good Examples

01

Format consistency — every example must use the exact same input-output structure; mixing separators or label styles teaches the model inconsistency

02

Coverage — examples should cover the cases the model needs to handle; for a three-class task, include at least one example of each class

03

Realistic inputs — use inputs that resemble what the model will actually see; trivially easy examples do not reflect real difficulty

04

Correct outputs — every example must show exactly what you want; a wrong example teaches the wrong pattern with the same force as a correct one

05

Conciseness — examples do not need explanation; the structure itself does the work — prose around examples dilutes the signal

How Many Examples?

Practical Guidance

More examples are better — up to a point. Two to three examples usually establish a reliable pattern for simple tasks. Four to six examples improve consistency for complex tasks or unusual output structures. Beyond ten, returns diminish and you consume valuable context window space. If the model still fails after six examples, the problem is usually in the task description, not the example count.

Simple tasks (2–3 examples)

Sentiment classification, label extraction, simple reformatting, fixed-category classification.

The output format is short and well-defined. Two examples establish the pattern reliably.

Complex tasks (4–6 examples)

Multi-field JSON extraction, nuanced tone matching, complex categorization with many edge cases.

More examples needed to cover the range of inputs and reduce format drift.

When to Use Few-Shot Prompting

01

Unusual output format — when the format is precise and hard to describe; showing it is faster and more reliable than explaining it

02

Consistent style — when you need the model to match a specific tone or writing style that is easier to demonstrate than describe

03

Zero-shot inconsistency — when direct prompting produces varying formats run to run and you need a stable output structure

04

Production systems — when output consistency is a functional requirement because downstream code parses the model's response

Summary

Key Takeaways
  • Few-shot prompting provides 2–5 input-output examples before the actual task request
  • Examples establish a pattern the model continues — more reliable than describing the pattern in words
  • Good examples are: format-consistent, representative, realistic, correct, and concise
  • Two to three examples work for simple tasks; four to six for complex or unusual output
  • If the model fails after six examples, the issue is usually the task description, not the example count
  • Most valuable when output format is precise, output style is specific, or zero-shot attempts are inconsistent

Need Help?

Ask the AI if you need help understanding few-shot prompting, how to write effective examples, how many examples to use for a given task, or when to choose few-shot over zero-shot prompting.