Skip to content
PromptayOpen the app

· 10 min read

Few-shot prompting: how to use examples to get consistent AI output

Few shot prompting examples you can copy: when examples beat instructions, how many to use, how to format them, and 5 worked templates for consistent output.

Few-shot prompting means showing the AI two to five finished examples of the output you want before you ask for a new one. It is the fastest way to get consistent format, tone and labels, because the model copies a pattern far more reliably than it follows a description of one. Below you will find when to use it, how to build good examples, the mistakes that break it, and five complete prompts you can copy today.

Zero-shot, one-shot and few-shot: the difference

The names describe how many examples sit inside your prompt.

  • Zero-shot: you give an instruction and no examples. "Classify this review as positive, negative or mixed." Fine for common tasks where the model already knows what good looks like.
  • One-shot: you give one example, then the new input. Useful for locking a format, but the model tends to copy that single example too closely, including its length and word choices.
  • Few-shot: you give several examples that vary in the right ways. The model can now separate what must stay the same (structure, labels, tone) from what should change (content).

Instructions tell the model the rules; examples show it the game being played. Most strong prompts use both. If you are new to the basic building blocks of a prompt, start with prompt engineering for beginners and come back here.

When examples beat instructions

Examples are worth the extra tokens in four situations.

  1. The format is fussy. Exact JSON keys, a fixed line order, a character limit on a headline. Showing three correct outputs removes the guesswork.
  2. The tone is hard to describe. "Friendly but not cheesy" means something different to everyone. Two sample replies define it in seconds.
  3. Your labels are custom. If your categories are "billing", "bug", "how-to" and "churn risk", the model needs to see where your boundaries sit, especially for the cases that could go either way.
  4. You need the same output a hundred times. Product descriptions, support replies, data cleanup. Examples make output 40 look like output 1.

Skip examples for one-off creative work and open questions, where you actually want variety.

How many examples to use

There is no magic number, but a practical rule works well:

  • 2 to 3 examples for format and tone tasks (rewrites, descriptions, replies).
  • One example per label, plus one tricky case for classification. With four categories, that is about five examples.
  • 3 to 5 examples for extraction, where you want to show missing fields, messy input and edge cases.

More is not automatically better: each example adds length and another accidental detail to copy. Add one only when it teaches something new. If output is still inconsistent after five, the cause is usually unclear instructions or contradictory examples.

How to pick diverse examples

Your examples should be identical where you want consistency and different everywhere else. Run through this checklist before you paste them in:

  • Vary the input. Short and long, simple and messy, polite and angry. If every sample input is a tidy two-line email, the model will struggle with a rambling one.
  • Cover every label or branch. A classifier that only sees positive and negative examples will rarely say "mixed".
  • Include one hard case. The review that praises the product but hates the shipping. The invoice with no date. Edge cases teach the boundary.
  • Keep the output structure identical. Same headings, same key order, same sign-off. This is the part you want copied.
  • Use realistic content. Placeholder text like "Product A is great" teaches the model to write placeholder text.

Format your examples with clear delimiters

The model needs to see exactly where each example starts, which part is input and which part is output. Consistent labels and separators do that job. Here is a skeleton you can reuse for any few-shot task:

Prompt
You are [role]. Your task is to [task].

Rules:
- [rule 1]
- [rule 2]
- Output only the [output type], nothing else.

Here are examples of correct output.

### Example 1
Input: [example input 1]
Output: [example output 1]

### Example 2
Input: [example input 2]
Output: [example output 2]

### Example 3
Input: [example input 3]
Output: [example output 3]

### Now do this one
Input: [your real input]
Output:

The labels are identical every time, the real task reuses them so the model sees it as the next item in the series, and the prompt ends on "Output:", which invites the answer and nothing else. XML-style tags such as <example> and </example> work just as well, and are a common convention in Anthropic's own prompting guidance. Pick one style and stay with it.

Common few-shot failures and how to fix them

The model copies your examples too literally. It reuses the same opening line, the same adjective, even the same product feature. Fix it by varying the surface details across examples and adding a rule: "Match the structure and tone of the examples, not their wording."

It leans toward the last example or the most common label. If three of your four classification examples are "positive", expect a lot of "positive". Balance the labels, shuffle their order, and do not always end with the same category.

It treats an example as the real task. This happens when the boundary between examples and the actual input is vague. Use a clearly different heading for the real input ("Now do this one") and put examples before the input, never after.

It invents fields you did not show. In extraction tasks, if an example contains a value that was not in its input, the model learns that guessing is allowed. Every output value in your examples must be traceable to its input. Show null for missing data.

Instructions and examples disagree. You say "under 50 words" and your examples run to 80. The model will usually follow the examples. Check every sample against your own rules. For more traps like this, see our list of common prompt mistakes.

Five worked few-shot prompting examples

Each prompt below is complete. Replace the bracketed parts and paste it into any assistant.

1. Classification: tagging support tickets

Prompt
Classify each customer message into exactly one category: billing, bug, how-to, churn-risk.
Reply with the category only, in lowercase.

Message: "I was charged twice for October, can you refund one?"
Category: billing

Message: "The export button does nothing when I click it on Safari."
Category: bug

Message: "How do I add a second user to my account?"
Category: how-to

Message: "Honestly thinking of switching, the app has been slow for weeks and nobody replies."
Category: churn-risk

Message: "Where can I download last month's invoice? I can't find it anywhere."
Category: how-to

Message: "[new customer message]"
Category:

The fifth example is the tricky case: it mentions an invoice but is really a navigation question, which teaches your billing versus how-to boundary.

2. Tone rewriting: from stiff to warm

Prompt
Rewrite each message in a warm, plain, confident tone. Keep every fact. Keep it about the same length. No exclamation marks.

Original: "Please be advised that your order has been delayed due to unforeseen circumstances."
Rewrite: "Quick heads-up: your order is running late. A supplier shipment arrived after we expected, and we'll update you as soon as it ships."

Original: "We regret to inform you that the workshop is fully booked."
Rewrite: "The workshop filled up faster than we planned, so we can't fit you in this time. Want a spot on the list for the next date?"

Original: "Your request has been received and will be processed in due course."
Rewrite: "Got it. We're on your request now and you'll hear back from us within two working days."

Original: "[your message]"
Rewrite:

3. Product descriptions with a fixed structure

Before:

Prompt
Write a product description for our lavender candle.

After:

Prompt
You write product descriptions for Wick & Willow, a small candle shop. Each description has: a 6 to 9 word headline, two sentences on how it feels to use, and one line starting "Details:" with size and burn time. Use only the facts given.

Facts: Cedar & Smoke candle, 220 g, 45 hour burn, soy wax, notes of cedarwood and campfire.
Description:
Headline: A cabin evening in a glass jar
Light it after dinner and the room settles into something slower. The cedar comes first, then a soft trace of woodsmoke that lingers without taking over.
Details: 220 g soy wax, about 45 hours of burn time.

Facts: Morning Citrus candle, 150 g, 30 hour burn, soy wax, notes of grapefruit and basil.
Description:
Headline: Bright, green and awake before the coffee
It smells like a kitchen with the windows open. Grapefruit keeps it sharp while basil stops it from tipping into sweet.
Details: 150 g soy wax, about 30 hours of burn time.

Facts: [your product facts]
Description:

Why the after works: the first prompt leaves length, structure and voice to chance. The second shows the pattern twice with different products, so the model copies structure and voice but writes new content.

4. Data extraction to JSON

Prompt
Extract the fields below from each email. Output valid JSON only. Use null when a field is not present. Never guess.

Fields: name, company, date_requested (YYYY-MM-DD), budget_usd (number), topic

Email: "Hi, this is Dana Ruiz from Lakeside Dental. Could we meet on March 4, 2026 to talk about a new booking page? Budget is around $3,500."
JSON: {"name": "Dana Ruiz", "company": "Lakeside Dental", "date_requested": "2026-03-04", "budget_usd": 3500, "topic": "new booking page"}

Email: "Hey, Sam here. Interested in a quote for logo work, no rush on timing."
JSON: {"name": "Sam", "company": null, "date_requested": null, "budget_usd": null, "topic": "logo work"}

Email: "[new email]"
JSON:

The second example shows that missing data becomes null, which stops the model inventing a company or a date.

5. Support replies in your house style

Before:

Prompt
Reply to this customer politely: "My discount code SPRING15 isn't working."

After:

Prompt
You answer support emails for Greenline Bikes. Every reply: greets by first name, acknowledges the issue in one sentence, gives the fix or next step, ends with "Ride safe, the Greenline team". Under 80 words.

Customer (Maya): "My order says delivered but there's nothing at my door."
Reply: Hi Maya, sorry, that's a frustrating one. Couriers sometimes mark parcels delivered a few hours early, so please give it until tomorrow evening. If it still hasn't shown up, reply here with your order number and we'll open a claim with the courier the same day. Ride safe, the Greenline team

Customer (Tom): "Can I swap the size on my helmet before it ships?"
Reply: Hi Tom, good timing. Your order hasn't left the warehouse yet, so we can change it. Just reply with the size you'd like and we'll update it today. Ride safe, the Greenline team

Customer ([name]): "[message]"
Reply:

Why the after works: "politely" is vague, so the model fills the gap with filler. The examples define polite for this brand: short, specific, one next step, a fixed sign-off. If you want a reply style that sounds like you rather than a brand, our guide to making ChatGPT write in your voice goes deeper.

Save time on the structure

Few-shot prompts need clear scaffolding around the examples: role, task, rules, output format. If you build prompts like these every day, a prompt generator such as Promptay turns one sentence into a structured prompt with role, task, context, format and constraints, and you just add your examples. You can also store reusable few-shot prompts as standing instructions; see these system prompt examples for how to do that.

Frequently asked questions

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

Zero-shot prompting gives the AI an instruction with no examples, while few-shot prompting includes several examples of finished output before the real request. Zero-shot works well for common, open tasks. Few-shot is better when you need a precise format, a specific tone or custom labels applied the same way every time.

How many examples should a few-shot prompt have?

Two to five examples cover most tasks. Use about three for tone and format work, and roughly one per category plus a tricky case for classification. Add an example only when it teaches something new, because extra examples make the prompt longer without always improving consistency.

Why does the AI copy my examples word for word?

This usually happens when your examples share the same surface details, such as the same opening phrase or the same length. Vary the content and wording across examples while keeping the structure identical, and add a rule telling the model to match the structure and tone, not the wording.

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

Yes. Few-shot prompting is a general technique that works in all major assistants, because every model learns patterns from the text in its prompt. Clear delimiters, consistent labels and balanced examples matter more than which assistant you use. For model-specific habits, see our comparison of ChatGPT, Claude and Gemini prompting.

Prompt templates for this topic