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.
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.
The more consistent your examples, the more accurately the AI mirrors the pattern.
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:
Zero-shot: You ask cold. The model uses general knowledge.
One-shot: You supply one example before the actual prompt.
Few-shot (2β5 examples): Multiple consistent examples.
Rule of thumb: Use as few examples as needed to make the pattern unambiguous. Three consistent examples usually beats one inconsistent one.
Pick 2β3 real inputs and their ideal outputs. Keep them representative, not cherry-picked extremes.
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.
After your examples, state the real input in exactly the same format. Never change the structure mid-prompt.
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.
(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.
(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".
(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.
(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.
(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.
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.