Few-shot prompting: how to teach an AI with a few examples

TL;DR: Few-shot prompting means putting a few worked examples of the task in your prompt, each showing an input and the output you want, so the model copies the pattern. It works best for fixed formats, labels and house style. Start with three to five varied examples, wrap them in tags, and check what they cost in tokens.

What few-shot prompting is

Few-shot prompting is showing the model a few finished examples of the job before you give it the real one. Each example pairs an input with the output you want. The model reads the pattern and applies it to your new input, with no training or settings involved. Everything happens inside the prompt.

A "shot" is one example. A prompt with no examples is zero-shot, a prompt with one is one-shot, and a prompt with several is few-shot. If you have ever pasted an old email and written "write it like this", you have already used it.

Examples show the target instead of describing it. "Keep it punchy and concrete" means different things to different people; two descriptions you actually published leave much less room for guessing.

Where the idea comes from

The name comes from machine learning, where "shots" are training examples. For prompts, the reference point is the GPT-3 paper, "Language Models are Few-Shot Learners" by Tom Brown and colleagues at OpenAI, published in 2020. It showed that a large enough model (GPT-3 had 175 billion parameters) could do a new task from a handful of examples written into the prompt, with no fine-tuning and no change to the model's weights.

The paper defined the three settings still used today. Zero-shot gives only an instruction. One-shot adds one demonstration. Few-shot adds as many as fit in the model's context window, which for GPT-3 was 2,048 tokens, typically 10 to 100 examples. Today's models follow instructions far better, so a few good examples usually do the job.

A worked example: sorting support tickets

Say you want every incoming support message sorted into one of five categories, with nothing else in the reply so a spreadsheet or helpdesk rule can read it. Here is the zero-shot version:

Zero-shot: instruction only
Sort each customer message into one category: Billing, Bug, Feature request, Account access or Other. Reply with the category only.

Message: [paste the customer message]
Category:

A strong model will get most messages right. Where it slips is the boundary cases. Is "my password stopped working after your update" a Bug or Account access? Does "the invoice shows the wrong company name" count as Billing? The instruction can't answer that. Examples can:

Few-shot: five examples, one per category
Sort each customer message into one category: Billing, Bug, Feature request, Account access or Other. Reply with the category only.

<examples>
<example>
Message: I was charged twice for my March invoice.
Category: Billing
</example>
<example>
Message: The export button does nothing when I click it in Firefox.
Category: Bug
</example>
<example>
Message: Could you add a dark mode to the dashboard?
Category: Feature request
</example>
<example>
Message: I changed phones and now the login code never arrives.
Category: Account access
</example>
<example>
Message: Do you have an office in Berlin?
Category: Other
</example>
</examples>

Message: [paste the customer message]
Category:

Three things are doing the work here. Every category appears once, so no label looks more likely than the others. The fourth example settles the login question: a sign-in problem is Account access even when something technical caused it. And the examples end with "Category:" followed by a single label, which shows the exact output format better than "reply with the category only" does on its own.

What the examples cost in tokens

Examples are not free. Every one is sent with every request, and you pay for it in input tokens, in speed and in room left in the context window. We measured the ticket prompt above with OpenAI's o200k_base tokenizer, the one used by GPT-5, GPT-4.1 and GPT-4o, with a sample message in place of the brackets. You can check your own prompts the same way in our free token counter.

Size of the ticket prompt as examples are added (o200k_base tokens)
VersionTokensCompared with zero-shot
Zero-shot (instruction and message)421x
One example691.6x
Three examples1162.8x
Five examples1603.8x

Each short classification example adds about 22 tokens. That is nothing in a chat, but it adds up in a pipeline: at 10,000 messages a month, the five-example version sends about 1.2 million more input tokens than the zero-shot one. Whether that is worth it depends on how many tickets the zero-shot version gets wrong.

Longer examples cost more. Two product descriptions of about 40 words each, used as style examples, took a prompt from 43 tokens to 191. A full sample email or report can run to several hundred tokens per example, so with long outputs, one or two good examples is often the right number.

If you call a model through the API with the same examples every time, put the instruction and examples first and the changing input last. OpenAI and Anthropic both cache a repeated prompt prefix for API users, so the fixed part at the start can be reused instead of processed from scratch each time.

How to pick good examples

The examples teach more than you intend. The model picks up their length, their tone, their opening words and their quirks, not only the rule you had in mind. Choose them with that in mind.

  • Use real inputs. Take examples from your actual tickets, emails or documents. Invented ones tend to be cleaner and easier than the real thing, so the model learns the easy case.
  • Cover the range. Include a short input and a long one, a polite one and an angry one, an obvious case and a borderline case. Anthropic's guidance asks for examples that are relevant, diverse and clearly separated from instructions.
  • Spend examples on the hard cases. The model already handles "I was charged twice". Use your examples to settle the boundaries where it guesses wrong.
  • Make the outputs exactly what you want. If one example output has a trailing full stop and another doesn't, expect a mix. Consistency in the examples is consistency in the answers.
  • Keep examples and instructions in agreement. OpenAI warns that when examples and instructions disagree, results suffer. If the instruction says "under 50 words", no example should run to 70.

How to format the examples

Separate the examples clearly from everything else, and label the parts inside each one. The model has to know where the instructions end, where each example starts and stops, and which part of an example is input and which is output.

  1. Put the instruction first. Say what the task is before you show it. Examples without an instruction leave the model to guess which pattern matters.
  2. Wrap the examples in tags. Anthropic recommends <example> tags inside an <examples> block. OpenAI's guide mentions markdown headings as well as XML tags. Pick one and stay with it.
  3. Use the same labels every time. "Message:" and "Category:" in every example, then again for the real input. The repeated labels are what the model latches on to.
  4. End where the answer should start. Finish the prompt with the output label ("Category:", "Description:") so the model continues in the same shape.

For a writing task, the same structure looks like this:

Few-shot template for house style
Write a product description for the product below in our house style. Match the length, tone and structure of the examples. Use only the facts given.

<examples>
<example>
Product: [an existing product: name, size, materials, price]
Description: [the description you published for it]
</example>
<example>
Product: [a second product, ideally a different kind]
Description: [its published description]
</example>
</examples>

Product: [the new product's facts]
Description:

"Use only the facts given" matters more in few-shot prompts than in most. Without it, the model may borrow details from the examples, such as a material, a size or a selling point, and put them in the new description.

How many examples to use

Start with three to five for short tasks, which is the range Anthropic recommends, and one or two for long outputs. Then adjust based on the results, not on a rule.

A starting point for the number of examples
TaskStart withWhy
Labels and categoriesOne per label, 3 to 6 in totalEvery label needs to be seen, and in balance
Extracting fields into a fixed format2 to 3The format is learned fast; add a case with a missing field
House style for short copy2 to 3Enough to show the voice without one example dominating
Long documents (emails, reports)1 to 2Each example is expensive, and the model copies long ones closely
Reasoning tasks on a thinking model0 first, then 1 to 2OpenAI advises trying zero-shot first on reasoning models

Add an example when you see the same mistake twice. Remove one when the outputs start to look like copies of it. If you need more than about ten to get consistent results, the task may need clearer instructions, a split into steps, or a different approach altogether.

Pitfalls to watch for

The model copies the examples too closely

Give one example of a LinkedIn post that opens with "Last Tuesday", and you may get five posts that open with a day of the week. The model can't tell which features are the point and which are accidents. Fix it by varying everything you don't care about (openings, topics, length within your range) and keeping constant only what you do care about. A line such as "match the tone, not the wording or the topic" also helps.

Label bias

If four of your six examples are labelled "Positive", the model leans toward Positive. Researchers measured this on GPT-3 in the 2021 paper "Calibrate Before Use" (Zhao and colleagues) and called it majority label bias. They also found the model favoured whatever answer was most common in its training data. Balance your labels, one or two per category.

Order

The same paper found a recency bias: labels that appear near the end of the prompt get predicted more often. A separate 2021 study by Lu and colleagues showed that just changing the order of the same examples could swing accuracy from close to state of the art to close to random guessing. These studies tested older models such as GPT-3. The habit still costs nothing: mix the labels, and don't end on two examples with the same answer.

Examples that teach the wrong thing

A 2022 study by Min and colleagues found that on classification tasks, replacing the labels in the examples with random ones barely hurt results. What mattered most was that the examples showed the format, the possible labels and the kind of input to expect. So get the format and the range of inputs right first, and still check every label.

When not to bother

Few-shot prompting is a tool for consistency, not a default. Skip it when:

  • The task is common and the format is simple. Summaries, translations and plain rewrites usually come out fine from a clear instruction. Try zero-shot prompting first and add examples only when you see a problem.
  • You want variety. Brainstorming headlines or ideas with examples in the prompt tends to produce variations on the examples.
  • The model has built-in reasoning and the task is hard thinking, not format. OpenAI's guidance for its reasoning models is to try without examples first. Anthropic notes that when you do use examples with its thinking models, it helps to show the method as well as the answer.
  • You can't find good examples. A weak or unrepresentative example can do more harm than none. Describe the output in words until you have real ones.

Few-shot is one of several techniques worth knowing side by side. For a tour of the others with a demo of each, see prompt engineering examples.

Two few-shot prompts to copy

1. Extract lead details into fixed fields
Pull these fields from the email below: company, contact name, budget, deadline. Use exactly the format in the examples. If a field is not in the email, write "not stated". Don't guess.

<examples>
<example>
Email: Hi, I'm Dana from Northwind. We have about $15k for a site refresh and need it live before the trade show on 3 May.
Fields:
company: Northwind
contact name: Dana
budget: $15,000
deadline: 3 May
</example>
<example>
Email: We're a small accounting firm looking for help with our newsletter. No rush. Thanks, Raj
Fields:
company: not stated
contact name: Raj
budget: not stated
deadline: not stated
</example>
</examples>

Email: [paste]
Fields:

Why it works: the second example shows what to do when information is missing, the case that most often produces invented answers.

2. Turn raw feedback into product notes
Rewrite each piece of feedback as a one-line note for our product team: what the customer is trying to do, what stops them, in under 20 words. Follow the examples.

<examples>
<example>
Feedback: Honestly the app is great but I gave up trying to share a report with my boss, there's no obvious way to do it??
Note: Wants to share a report with a manager; can't find a share option.
</example>
<example>
Feedback: Third time this month the sync failed overnight. We lose a morning re-entering orders.
Note: Needs overnight order sync; it fails repeatedly and costs staff time.
</example>
</examples>

Feedback: [paste]
Note:

Let the right experts write your prompt

Prompt Expert is an AI prompt generator that brings the right experts to every job. They ask a few questions, read your website and files, and write the prompt for ChatGPT, Claude or Gemini with your real facts, working together when a job needs more than one.

See how it works

Questions

What is few-shot prompting?

Few-shot prompting is including a few examples of the task in your prompt, each showing an input and the output you want. The model follows the pattern of the examples when it answers your real input.

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

A zero-shot prompt gives only an instruction; a few-shot prompt adds worked examples. Zero-shot is shorter and cheaper and is enough for many tasks. Few-shot gives more consistent formats, labels and tone.

How many examples should a few-shot prompt have?

Start with three to five for short tasks and one or two for long outputs such as emails or reports. Add an example when the same mistake repeats, and remove one when answers start to copy it.

Does few-shot prompting work in ChatGPT, Claude and Gemini?

Yes. It is plain text in the prompt, so it works in any chat assistant or API. Anthropic recommends wrapping examples in example tags for Claude, and the same clear separation helps other models.

Do examples make a prompt more expensive?

Yes, because every example is sent with every request. In our test, five short classification examples made a prompt 3.8 times longer. For one-off chats this doesn't matter; in high-volume pipelines it adds up.

Is few-shot prompting the same as fine-tuning?

No. Few-shot prompting puts examples in the prompt and changes nothing in the model. Fine-tuning trains the model on many examples so the behavior is built in, which costs more effort up front but makes each prompt shorter.

Sources