Few-shot prompting is one of the most powerful techniques for getting consistent, structured output from AI — and it requires no special setup, no APIs, no fine-tuning. Just examples inside the prompt.
Here's how it works, when to use it, and 5 copy-paste templates to get started.
What Is Few-Shot Prompting?
Few-shot prompting is a technique where you give an AI model one to several worked examples inside the prompt before asking your actual question. Instead of explaining the rules in words, you show the pattern and let the model infer what to do.
- Zero-shot: No examples — the model uses its general training.
- One-shot: One example before the actual request.
- Few-shot: Two to five consistent examples before the actual request.
The more consistent your examples, the more accurately the AI mirrors the pattern.
Why Examples Beat Instructions
Telling an AI "be concise" is vague. Showing it two concise answers followed by a new question makes the target concrete. The model learns format, tone, length, and structure simultaneously from a single demonstration — no lengthy rule explanation required.
Analogy: training a new employee with an example memo beats handing them a style guide. They pattern-match instantly.
The technique is especially powerful for:
- Consistent tone/voice (marketing copy, social posts)
- Structured output (JSON, tables, bullet lists in a specific format)
- Domain-specific tasks (legal summaries, medical triage notes)
- Classification (sentiment labels, priority tags)
Zero-Shot vs. One-Shot vs. Few-Shot: What Changes
Zero-shot: You ask cold. The model uses general knowledge.
- Risk: Generic output, wrong format, inconsistent length.
- Best for: Simple, well-defined tasks (translation, grammar fix).
One-shot: You supply one example before the actual prompt.
- Risk: Model may treat it as a specific answer, not a pattern.
- Best for: Short tasks where the pattern is obvious.
Few-shot (2–5 examples): Multiple consistent examples.
- Risk: Longer prompts; edge cases can confuse the model if examples conflict.
- Best for: Format-sensitive or tone-sensitive tasks.
Rule of thumb: Use as few examples as needed to make the pattern unambiguous. Three consistent examples usually beats one inconsistent one.
How to Build a Few-Shot Prompt in 3 Steps
Step 1 — Write your examples first
Pick 2–3 real inputs and their ideal outputs. Keep them representative, not cherry-picked extremes.
Step 2 — Format consistently
Use the same delimiters every time:
Input: ...
Output: ...
or:
Q: ...
A: ...
Inconsistent delimiters confuse the model about where examples end and the real question begins.
Step 3 — Place the actual task last
After your examples, state the real input in exactly the same format. Never change the structure mid-prompt.
Before/After: Zero-Shot vs. Few-Shot for Tone
The task: Rewrite a bland product description to sound like a confident, direct e-commerce brand.
Zero-shot (generic result):
Rewrite this product description to sound more engaging:
"This is a water bottle. It holds 32 oz."
Typical output: "Stay hydrated with our stylish 32 oz water bottle!" — still generic.
Few-shot (on-brand result):
Rewrite product descriptions to match this tone — punchy, direct, confident:
Input: "This is a backpack. It has multiple pockets."
Output: "Built for how you actually move. Five pockets, zero wasted space."
Input: "This is a desk lamp. It has adjustable brightness."
Output: "Dial it from 'coffee-fueled focus' to 'Sunday morning ease.' Your eyes, your rules."
Now rewrite:
Input: "This is a water bottle. It holds 32 oz."
Output:
Typical output: "Thirty-two ounces of shut up and drink more water." — on-brand.
Examples teach the model a format. If what you need is a procedure instead — the model showing its work step by step — that is a different tool: chain-of-thought prompting. The two combine well, and knowing which one your task needs saves a lot of failed attempts.
5 Copy-Paste Few-Shot Templates
1. Consistent Brand Voice
(Role) You are a brand voice editor.
(Context) The examples below show our tone: confident, direct, slightly cheeky.
Example 1 — Input: [bland sentence 1] Output: [on-brand rewrite 1]
Example 2 — Input: [bland sentence 2] Output: [on-brand rewrite 2]
Example 3 — Input: [bland sentence 3] Output: [on-brand rewrite 3]
(Task) Rewrite the following using the same tone:
Input: [your sentence here]
(Format) Output only the rewritten sentence.
2. Structured Data Extraction
(Role) You are a data extraction assistant.
(Context) Extract structured fields from text:
Example 1 — Input: "[raw text]" Output: Name: [X], Date: [Y], Amount: [Z]
Example 2 — Input: "[raw text]" Output: Name: [X], Date: [Y], Amount: [Z]
(Task) Extract fields from this text:
Input: [your raw text]
(Format) Return Name, Date, Amount on separate lines. If missing, write "N/A".
3. Sentiment Classification
(Role) You are a customer review classifier.
(Context) Classify reviews as Positive, Neutral, or Negative:
Example 1 — "The shipping was fast and the product works well." → Positive
Example 2 — "It's okay, nothing special." → Neutral
Example 3 — "Broke after two days. Terrible quality." → Negative
(Task) Classify this review:
"[your review text]"
(Format) Output one word only: Positive, Neutral, or Negative.
4. Tone Transformation (Casual to Formal)
(Role) You are a business writing coach.
(Context) Transform casual messages to professional email tone:
Example 1 — Casual: "Hey, any update on this?" Formal: "Could you please provide an update on the status of this item?"
Example 2 — Casual: "That doesn't work for us." Formal: "Unfortunately, that approach does not align with our current requirements."
(Task) Transform the following message:
Casual: "[your casual message]"
(Format) Output only the formal version.
5. Headline Variants
(Role) You are a conversion-focused copywriter.
(Context) Generate headlines that match this style — specific, benefit-first, no fluff:
Example 1 — Topic: productivity app → "Cut Your Task List in Half Before Lunch"
Example 2 — Topic: online course → "Learn SQL in 30 Days — Even If You've Never Coded"
(Task) Write 3 headlines for:
Topic: [your topic]
(Format) Numbered list, one line each.
FAQ
What is few-shot prompting in simple terms?
Giving an AI two to five examples of input-output pairs before your actual request. The AI reads the pattern from your examples and applies it to the new input — no rule explanation needed.
How many examples should a few-shot prompt have?
Two to three is the practical sweet spot. One risks the model treating it as the specific answer; more than five adds length without proportional accuracy gain.
What is the difference between zero-shot and few-shot prompting?
Zero-shot gives no examples — the AI relies entirely on its training. Few-shot supplies examples inside the prompt, so the model infers format, tone, and structure from demonstrations.
When should I use few-shot instead of zero-shot?
When output format matters (specific structure, tone, or label set), when zero-shot keeps giving generic results, or when the task involves a style the model hasn't seen enough of in training.
Does few-shot prompting work with all AI models?
Yes. The technique works with GPT-4, Claude, Gemini, and most instruction-tuned models. Larger models need fewer examples; smaller models may need more.
Can I combine few-shot prompting with a role instruction?
Yes — and you should. Adding a role before your examples sharpens context. The role sets who the AI is; the examples set the format. Together they constrain output far better than either alone.
Originally published at my-blog.org.
Top comments (0)