AI

Few Shot Prompting: How to Use Examples in Prompts

Few shot prompting explained: how examples in a prompt steer an AI model, how many to use, how to pick and format them, and when to fine-tune instead.

By OmniAI Editorial · Nov 22, 2026 · 15 min read

Few shot prompting is the technique of putting a handful of worked examples, input followed by the desired output, into your prompt so an AI model copies the pattern for a new input. It needs no training: the model picks up the task, format, tone and labels from the examples in its context window. Two to five good examples are usually enough to make outputs far more consistent than instructions alone.

This guide goes deeper than the basic definition. It covers what is few shot prompting and why it works, zero shot vs few shot prompting, how many examples to use, how to choose, order and format them, few shot prompting examples for classification, extraction, rewriting and code, dynamic example selection, the token cost, and how few shot prompting vs fine tuning compares.

What Is Few Shot Prompting?

Few shot prompting means teaching a model a task by showing it a few demonstrations inside the prompt. Each demonstration is a pair: an example input and the exact output you want. After the examples comes the real input, and the model continues the pattern.

Classify the sentiment of each review as positive, negative or mixed.

Review: The battery lasts two days and the screen is gorgeous.
Sentiment: positive

Review: Arrived broken and support never replied.
Sentiment: negative

Review: Great camera, but it overheats when I play games.
Sentiment: mixed

Review: Setup took five minutes and it just works.
Sentiment:

The model answers "positive" and, just as importantly, answers with one word in the same format as the examples.

The term comes from the GPT-3 paper, "Language Models are Few-Shot Learners" (Brown et al.), which showed that a 175-billion-parameter model could do new tasks from a few demonstrations given "purely via text," without any gradient updates or fine-tuning. Researchers call this in-context learning: the model's weights don't change; the examples only shape its next prediction.

Zero Shot vs Few Shot Prompting

The names describe how many examples you give:

Zero shotOne shotFew shot
Examples in the promptNoneOneUsually 2 to 5, sometimes more
What guides the modelInstructions onlyInstructions plus one patternInstructions plus several patterns
Prompt lengthShortestShortLonger; costs more tokens
Output consistencyVaries mostBetter format, can over-copy the single exampleMost consistent
Best forSimple, common tasks; quick testsShowing an output formatCustom labels, strict formats, specific tone, edge cases

Modern models follow instructions well, so zero shot is the right starting point for common tasks like summarizing or translating. Move to few shot when the output must follow a specific format, use your own labels, match a house style, or handle tricky cases the instructions don't capture. Our explainer on zero shot learning covers the zero-shot side in depth, including how models classify into labels they've never seen.

A one shot prompt is useful for showing a format, but with a single example the model tends to copy its length, wording and even content too closely. Two or three varied examples teach the pattern without anchoring on one instance.

How Few Shot Prompting Works

The model isn't learning in the training sense. It predicts the most likely continuation of the text, and examples change what "most likely" means. Research has shown what the examples actually teach.

A study by Min et al., "Rethinking the Role of Demonstrations," found that randomly replacing the labels in demonstrations barely hurt performance across 12 models. What mattered was that the examples showed the model the label space (which answers are possible), the distribution of the input text (what inputs look like) and the overall format of the sequence. In other words, examples mostly teach the shape of the task.

That doesn't mean wrong labels are harmless in practice: on harder or subtler tasks, and with your own business rules, correct examples still matter. But it explains why format consistency is so powerful, and why examples that look like your real inputs beat polished but unrepresentative ones.

Examples also bring risks. "Calibrate Before Use" (Zhao et al.) found few-shot results can be unstable depending on the prompt format, the choice of examples and even their order, with models biased toward answers placed near the end of the prompt or common in their training data. "Fantastically Ordered Prompts" (Lu et al.) found that ordering alone can make the difference between near state-of-the-art and random-guess performance on some tasks. Newer, larger models are much less fragile than the models in those studies, but the lesson still applies: test your examples, don't assume.

Three light cards in a row, each holding a grey square and an ink line, then an ink arrow to a fourth card where the square is orange.
Each example pairs an input with an output; the model continues the pattern.

How Many Examples Should You Use?

Start with three to five. Anthropic's prompting guide recommends including 3 to 5 examples for best results, and that matches what works across most providers.

Rules of thumb:

  • Two or three are enough to fix a format or tone.
  • Three to five suit classification with several labels: at least one example per label you care about.
  • More can help for complex extraction or rare edge cases, but returns shrink quickly and every example costs tokens on every request.
  • Fewer is better if outputs start copying examples too literally, such as repeating phrases or names from them.

If you need dozens of examples to get acceptable results, that's a sign the task may be better served by fine-tuning or by rethinking the instructions.

How to Choose Good Examples

Example quality matters more than quantity. Anthropic's guide asks for examples that are relevant (mirror your real use case), diverse (cover edge cases and vary enough that the model doesn't pick up unintended patterns) and structured (clearly separated from instructions). OpenAI's prompting guide similarly advises showing "a diverse range of possible inputs with the desired outputs."

In practice:

  1. Use real inputs. Take examples from actual data, anonymized if needed, not invented ones that are cleaner than reality.
  2. Cover every label or branch. If there are three categories, show all three. A label that never appears is a label the model will under-use.
  3. Include a hard case. Show the tricky input, like sarcasm, a missing field or a mixed review, and how to handle it.
  4. Vary length and wording. If every example is two sentences long, outputs will be two sentences long.
  5. Balance the labels. Three positive examples and one negative nudges the model toward positive.
  6. Keep outputs exactly as you want them, including capitalization, punctuation, JSON keys and field order. The model copies details.

Formatting Few Shot Prompts

Make it obvious where each example starts and ends, and where the real input is. Three common formats:

Labeled blocks in one prompt work everywhere:

Extract the company and funding amount as JSON.

<examples>
<example>
Input: Acme raised a $12 million Series A led by Northwind.
Output: {"company": "Acme", "amount_usd": 12000000}
</example>
<example>
Input: Bluebird closed $3.5M in seed funding this week.
Output: {"company": "Bluebird", "amount_usd": 3500000}
</example>
<example>
Input: Shares of Contoso fell after the earnings call.
Output: {"company": "Contoso", "amount_usd": null}
</example>
</examples>

Input: Zephyr Labs announced an $80 million Series C.
Output:

Anthropic recommends wrapping examples in <example> tags, with several inside <examples>, so Claude can tell them apart from instructions. Notice the third example: it teaches the model what to do when there's no funding amount, which instructions often forget.

Chat turns suit chat APIs. You write each example as a user message followed by an assistant message, then add the real user message:

messages = [
    {"role": "user", "content": "Rewrite formally: hey, can u send the deck?"},
    {"role": "assistant", "content": "Could you please send me the presentation?"},
    {"role": "user", "content": "Rewrite formally: we're gonna be late, sorry"},
    {"role": "assistant", "content": "Please accept our apologies; we will arrive late."},
    {"role": "user", "content": "Rewrite formally: thx, looks good to me"},
]

The model sees a conversation where it has already answered in the right style twice, so it continues the same way.

System or developer message examples keep examples separate from user input. OpenAI's guide shows examples placed in the developer message under an examples section, after the identity and instructions, and notes that reused content like examples should come before the changing input so it can be cached.

Few Shot Prompting Examples

Here are few shot prompting examples for four common tasks, with what each set of examples teaches.

TaskWhat to show in the examplesWhy examples beat instructions here
Ticket classificationOne ticket per category, including an ambiguous one with the rule for tiesTeaches your custom categories and boundaries
Data extractionInputs with all fields, missing fields and messy formatting, each with the exact JSONFixes keys, types and null handling
Style rewritingBefore-and-after pairs in your brand voiceTone is easier to show than describe
Code generationShort functions in your project's conventions (naming, error handling, docstrings)The model adopts local patterns, not generic ones
Grading or evaluationAnswers with the score and a one-line reason, at several score levelsCalibrates what a 3 vs a 5 means

A support-ticket example, written as a template you can adapt:

Classify each support ticket as billing, bug, feature_request or other.
If a ticket mentions both a charge and a bug, choose billing.

Ticket: I was charged twice this month.
Category: billing

Ticket: The export button does nothing in Firefox.
Category: bug

Ticket: Please add dark mode to the mobile app.
Category: feature_request

Ticket: The app crashed and then I got charged for a plan I cancelled.
Category: billing

Ticket: {new_ticket}
Category:

The fourth example demonstrates the tie-break rule from the instructions, so the model sees it applied rather than only stated.

Few Shot Chain of Thought

You can combine examples with reasoning. In few shot chain of thought, each example shows the steps that lead to the answer, not just the answer, so the model reasons the same way on the new input. It helps on math, logic and multi-step decisions. Our guide to chain of thought prompting covers the technique and its variants in detail.

With reasoning models that think before answering, examples still help. Anthropic's guide notes that worked examples shape how Claude approaches similar problems in its thinking, and suggests presenting each as the problem, the method to apply and the expected answer. OpenAI's guide says its reasoning models do better with high-level guidance than with step-by-step instructions, so with those models keep examples focused on the desired output rather than scripting every reasoning step.

Dynamic Few Shot Prompting

Fixed examples work for narrow tasks. When inputs vary a lot, you can choose examples per request instead: keep a library of good input-output pairs, embed them, and for each new input retrieve the few most similar ones to put in the prompt. This is sometimes called dynamic or retrieval-based few shot prompting, and frameworks like LangChain ship example selectors that pick examples by semantic similarity.

It's especially useful for:

  • Support bots with many product areas, where the best example depends on the question.
  • Extraction from many document types.
  • Text-to-SQL, where similar past questions with correct queries are the best teacher.

The trade-off is that changing examples per request breaks prompt caching on that part of the prompt, and you need to maintain the example library.

The Cost of Few Shot Prompting

Examples are input tokens, and you pay for them on every call. A worked example with simple numbers:

Value
Examples per prompt5
Tokens per exampleabout 120
Extra tokens per requestabout 600
Requests per day100,000
Extra input tokens per day60 million
Cost at an example price of $3 per million input tokens$180 per day
Same tokens as cache reads at 0.1× the input price$18 per day, plus occasional cache writes

Two ways to keep the cost down:

  • Put fixed examples at the start of the prompt and use prompt caching, so providers bill repeated examples at a fraction of the normal input price.
  • Trim examples to the shortest ones that still teach the pattern, and remove any that don't change results when you test without them.
Two light prompt shapes: the left short with one grey block and a short ink bar below, the right tall with four grey blocks above one orange block and a long ink bar below.
Every example adds tokens to every request.

Few Shot Prompting vs Fine Tuning

Both teach a model your task; they do it in different places.

Few shot promptingFine tuning
Where the examples goIn the prompt, every requestInto the model's weights, once
Examples needed2 to 10Hundreds to thousands
Setup timeMinutesHours to days, plus data preparation
Cost structurePay for example tokens on every callTraining cost up front; shorter prompts later
Changing behaviorEdit the promptRetrain
Works with any modelYesOnly models you can fine-tune
Best forFormats, labels, tone, prototypes, changing requirementsVery high volume, strict style, specialized behavior prompts can't reach

Start with few shot prompting: it's faster, cheaper to change and often good enough. Consider fine-tuning when the prompt needs so many examples that token costs or latency hurt, or when even good examples can't get consistent results. Our prompt engineering guide covers how examples fit with the other techniques you'd try first.

Few Shot Prompting vs RAG and Other Techniques

People often mix up few shot prompting with other ways of adding content to a prompt. They solve different problems:

TechniqueWhat you add to the promptWhat it fixes
Few shot promptingInput-output examplesHow to answer: format, labels, tone
Retrieval-augmented generation (RAG)Relevant documents or factsWhat to answer with: knowledge the model lacks
Chain of thoughtA request to reason step by step, or reasoning examplesHow to think through multi-step problems
System promptRole, rules and constraintsOverall behavior across a conversation

The distinction matters when something goes wrong. If answers are in the right format but contain wrong or outdated facts, more examples won't help; the model needs the facts, which is a RAG problem. If the facts are right but the structure, length or labels are off, that's where examples shine. Many production prompts combine all four: a system prompt with rules, retrieved documents, a few examples of the answer format and, for hard questions, room to reason.

Dynamic few shot prompting, described above, is itself a small form of retrieval: instead of retrieving facts, you retrieve the most relevant examples.

How to Test Your Examples

Treat your examples like code: test them.

  1. Build a small evaluation set of 20 to 50 real inputs with known correct outputs, separate from your examples.
  2. Run zero shot first to get a baseline.
  3. Add examples and compare accuracy and format errors.
  4. Shuffle the example order and run again; big swings mean your examples are fragile.
  5. Remove one example at a time to see which ones earn their tokens.
  6. Re-test when you change models. A new model can need fewer examples, or behave differently with the same ones.

Common Mistakes

  • Examples that contradict the instructions. The model follows the examples. If the instructions say "one sentence" and examples have three, expect three.
  • Unbalanced labels. Most examples with one label skew answers toward it.
  • Leaking example content. Distinctive names or facts from examples show up in outputs; use neutral placeholders.
  • No hard cases. The model handles easy inputs anyway; examples should teach the edge cases.
  • Unclear boundaries. Without tags or consistent labels, the model may treat an example as part of the input.
  • Never testing without them. Strong models sometimes do better zero shot; check that the examples help.

FAQ

What is few shot prompting in simple terms?

It's showing an AI model a few examples of what you want, each with an input and the right output, before giving it the real input. The model copies the pattern, so you get answers in the format and style you showed.

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

Zero shot prompting gives only instructions. Few shot prompting adds a handful of worked examples. Few shot is usually more consistent in format and labels, at the cost of a longer prompt.

How many examples are needed for few shot prompting?

Usually three to five. Two can be enough for a simple format; complex classification may need one example per label plus a hard case. If you need many more, consider fine-tuning.

Is few shot prompting the same as fine-tuning?

No. Few shot prompting puts examples in the prompt and doesn't change the model. Fine-tuning trains the model on many examples so the behavior is built into its weights.

Does few shot prompting work with reasoning models?

Yes, especially for output format and approach. Providers advise keeping guidance high level for reasoning models, so use examples to show the result you want rather than scripting every reasoning step.

All articles

Read next

Language

EnglishEnglish · en TürkçeTurkish · tr DeutschGerman · de العربيةArabic · ar

Account

Enter your email. We’ll send you a sign-in link and a 6-digit code. No password needed.

Sign in

Theme

Language

Show our email address

To keep spam out of our inbox, please confirm your own email first. We will send you a 6-digit code.

We send codes only to these providers: gmail.com, googlemail.com, outlook.com, hotmail.com, live.com, msn.com, proton.me, protonmail.com, pm.me, icloud.com, me.com, mac.com, yahoo.com, aol.com, gmx.de, gmx.net, web.de, t-online.de, yandex.com, omniai.blog