AI Guides · 9 min read

What Is Few-Shot Prompting? Examples That Steer Model Output

Few-shot prompting puts a few input-output examples in a prompt so a model can follow the same pattern on a new task, unlike zero-shot prompts with no examples.

A dark editorial still life of a few marked sample tiles leading to a new unmarked tile shaped in the same pattern, with no text or logos

Few-shot prompting is a technique where you place a small set of input-output examples directly inside a prompt so a language model learns the pattern for a new task without fine-tuning. By showing what a correct response looks like, few-shot examples steer output format, tone, phrasing, and structure on the next input.

How Does Few-Shot Prompting Work?

Few-shot prompting works because large language models detect patterns and relationships across the examples in a prompt and extend those same patterns to a new user request. OpenAI calls this technique few-shot learning and describes it as a way to steer a model toward a new task using a handful of input/output examples in the prompt. Anthropic refers to the same approach as few-shot or multishot prompting, while Google groups it under few-shot prompts.

In an API request, those examples sit alongside your task instructions before the live input you want the model to process. As of November 29, 2026, OpenAI’s prompt engineering guide notes that you typically place examples inside a developer message, often following an order of Identity, Instructions, Examples, and Context. Anthropic’s prompting documentation recommends separating instructions, context, examples, and variable inputs with XML tags so Claude can tell each part apart unambiguously.

Beyond formatting and tone, examples can also demonstrate reasoning steps. Anthropic’s thinking guidance notes that multishot examples work with extended thinking: presenting each worked example as a problem, the method to apply, and the expected answer shapes how Claude approaches similar problems inside its own thinking blocks.

Few-Shot vs. Zero-Shot Prompting

Few-shot prompting and zero-shot prompting differ on one structural choice: whether the prompt includes sample input-output pairs. Google’s Gemini API prompt design documentation as of November 29, 2026 defines the two terms directly: “Prompts that contain a few examples are called few-shot prompts, while prompts that provide no examples are called zero-shot prompts.”

Zero-shot prompting relies purely on your written instructions or question. That keeps the prompt short, yet leaves more room for the model to guess your preferred length, tone, or schema. Google’s prompt design guide goes so far as to state: “We recommend to always include few-shot examples in your prompts. Prompts without few-shot examples are likely to be less effective. In fact, you can remove instructions from your prompt if your examples are clear enough in showing the task at hand.”

Google illustrates that behavioral shift with a snow-formation comparison run on gemini-2.5-flash. When given a zero-shot prompt asking which of two explanations of how snow forms is best, the model favored the longer explanation. When the prompt included two few-shot examples that selected shorter explanations over longer ones, the model followed the demonstrated preference and picked the shorter snow explanation, labeled Explanation2.

Dimension Zero-shot prompt Few-shot prompt
Examples in prompt None A small set of input-output pairs
Primary steering mechanism Written instructions and task framing Demonstrated patterns, format, and phrasing
Best-documented strength Minimal prompt length for simple requests Consistent formatting, scoping, tone, and structure
Key risk noted in docs Less effective output matching when preferences are implicit Overfitting if too many examples are included
API token footprint Lower input token count Higher input token count from the added examples

When someone refers to one-shot prompting in everyday conversation, they simply mean a prompt containing a single example. In official vendor documentation from OpenAI, Anthropic, and Google as of November 29, 2026, the main split remains zero-shot versus few-shot or multishot prompting.

How OpenAI Structures a Few-Shot Prompt

OpenAI’s prompt engineering guide provides a concrete developer message showing how instructions and few-shot examples reinforce one another for sentiment classification. Notice how the prompt sets an identity, establishes strict output rules, and then gives three labeled examples in consistent XML tags:

# Identity

You are a helpful assistant that labels short product reviews as
Positive, Negative, or Neutral.

# Instructions

* Only output a single word in your response with no additional formatting
  or commentary.
* Your response should only be one of the words "Positive", "Negative", or
  "Neutral" depending on the sentiment of the product review you are given.

# Examples

<product_review id="example-1">
I absolutely love this headphones — sound quality is amazing!
</product_review>

<assistant_response id="example-1">
Positive
</assistant_response>

<product_review id="example-2">
Battery life is okay, but the ear pads feel cheap.
</product_review>

<assistant_response id="example-2">
Neutral
</assistant_response>

<product_review id="example-3">
Terrible customer service, I'll never buy from them again.
</product_review>

<assistant_response id="example-3">
Negative
</assistant_response>

Several design details make this sample work cleanly. First, the # Instructions block states that the model must output only a single word (Positive, Negative, or Neutral) with no commentary. Every <assistant_response> block obeys that exact rule. Second, the three <product_review> inputs cover all three sentiment classes rather than repeating three positive reviews. Third, the XML tags and id attributes give every input and expected output an identical boundary, making the pattern easy for the model to continue when the actual user review arrives.

How Should You Choose Few-Shot Examples?

Choosing few-shot examples requires balancing realism, variety, and strict structural consistency. Across OpenAI, Anthropic, and Google documentation as of November 29, 2026, three selection rules appear repeatedly.

Relevance and diversity

Examples should mirror the real inputs your application expects while covering enough variation to prevent narrow assumptions. Anthropic’s prompting best practices advise making examples relevant to your actual use case and diverse enough to cover edge cases so Claude avoids picking up unintended patterns. OpenAI similarly asks developers to show a diverse range of possible inputs paired with the desired outputs, and Google advises using specific and varied examples to narrow the model’s focus.

If you already have a small starter set, you do not have to write every variation by hand. Anthropic notes that you can ask Claude to evaluate your existing examples for relevance and diversity, or to generate additional examples based on your initial set, before you lock them into production prompts.

Consistent formatting and clear delimiters

Formatting consistency matters as much as the words inside each example. Google’s prompt design guide dedicates a specific subsection to this point: “Make sure that the structure and formatting of few-shot examples are the same to avoid responses with undesired formats.” Google highlights XML tags, white spaces, newlines, and example splitters as details you need to keep uniform across every sample.

Anthropic gives matching structural advice for Claude. Wrapping individual examples and the parent example container in XML tags keeps the model from confusing demonstration text with live instructions or user input. When a model sees identical wrappers and spacing across every example, it treats the wrapper pattern as part of the target specification.

How many examples to include

No universal example count applies across every model family and task. Vendors give different levels of specificity in their documentation as of November 29, 2026:

  • Anthropic: In its Claude prompting best practices, Anthropic states, “Include 3–5 examples for best results.” That figure is specific to Anthropic’s guidance for Claude.
  • OpenAI: OpenAI’s few-shot learning section avoids a fixed count, describing the technique as including “a handful” of diverse input/output examples.
  • Google: Google’s Gemini prompt design guide advises experimentation, noting that Gemini models often pick up patterns from a few examples while warning that including too many can cause the model to overfit its response.

Starting with a small, diverse set like three to five examples and testing against real edge cases lets you add or trim samples based on actual model outputs rather than guessing a magic number.

Why Do Few-Shot Examples Fail?

Few-shot examples fail when the demonstrations teach an ambiguous, conflicting, or overly rigid pattern. Even a strong frontier model can produce erratic output when the examples in the prompt pull it in competing directions.

Contradictory examples

Contradictory examples teach an inconsistent rule. If two samples contain nearly identical inputs yet receive different labels, or if one example returns a single sentence while another returns a bulleted list, the model has no reliable pattern to extend. Google’s snow-explanation illustration shows why alignment across examples matters: both few-shot examples consistently preferred the shorter explanation, which shifted the model’s selection cleanly. When examples disagree with one another on style, length, or classification boundaries, that steering signal breaks down.

Examples that conflict with system or developer instructions

Mixed signals between your written instructions and your few-shot examples are another common source of prompt failure. In OpenAI’s official structure, Identity and Instructions come before Examples inside the developer message. If your # Instructions section forbids commentary and asks for a single word, yet one of your # Examples includes an explanatory sentence alongside the label, the prompt contradicts itself.

Whenever you revise instructions, update the examples in the same edit. Checking every <assistant_response> or output block against every constraint in your system or developer instructions ensures the examples reinforce the rules rather than demonstrating an exception to them.

Overfitting from too many examples

Adding more examples eventually stops helping and starts hurting generalization. Google explicitly warns in its Gemini documentation that if you provide too many examples, the model may start to overfit the response to those examples. Instead of learning the underlying rule, the model may cling too tightly to surface phrasing, length, or quirks in the sample set when confronted with unfamiliar inputs.

How Do Few-Shot Examples Affect Tokens and Prompt Caching?

Few-shot examples consume input tokens on every API call because they are sent inside the prompt alongside your instructions and user query. Every extra sample increases the total input length, which directly affects what you pay and how much context window remains for user data and model output, as explained in our guide on what a token in AI is.

OpenAI’s prompt engineering guide points out a practical layout optimization for keeping repeated few-shot prompts efficient: place reusable examples and reference material before the changing user input. Keeping static instructions and few-shot examples at the top of the prompt preserves a shared prefix across requests, making that prefix eligible for prompt caching. When the user message at the end changes from call to call, the leading example block stays identical.

FAQ

What is the difference between zero-shot and few-shot prompting?

Zero-shot prompting provides no input-output examples in the prompt, relying solely on your written instructions or query. Few-shot prompting includes a small number of examples so the model can see the pattern, formatting, tone, or classification rule you want and apply it to a new input.

How many examples should a few-shot prompt include?

No single count fits every model or task. As of November 29, 2026, Anthropic recommends 3–5 examples for best results with Claude, OpenAI describes using a handful of diverse examples, and Google advises experimenting because adding too many examples can cause the model to overfit its response.

Can few-shot examples replace written instructions?

Sometimes, depending on how clear the examples are. Google’s Gemini prompt design guide notes that you can remove written instructions if your few-shot examples clearly demonstrate the task. However, OpenAI and Anthropic both show structured prompts where instructions and XML-tagged examples work together in separate sections.

Why do few-shot prompts sometimes ignore formatting rules?

Models often miss formatting rules when examples use inconsistent newlines, white space, splitters, or XML tags, or when the examples themselves violate your system or developer instructions. Keeping structure identical across every example and verifying that each sample obeys every stated constraint resolves those mixed signals.

Sources

Written by

Chunyu Cai

Chunyu Cai is the CEO of Lotook, LLC and an entrepreneur who writes about AI models, agents, and how they change everyday work. Chunyu holds a master's degree from Imperial College London.