Section 10.2.3 : Few-shot prompting — Learning by example
🎯 Learning objective
Mastering few-shot prompting: guiding the model by providing concrete examples to obtain results that follow exactly the desired format, tone, and logic. This is the most powerful technique for consistency and customization.
Few-shot: teaching by example
Few-shot prompting involves providing a few examples (typically 2 to 5) before asking the actual question. The model learns the pattern from the examples and applies it to the new input. It's a form of in-context learning — the model isn't retrained, it understands the pattern from the examples.
Imagine you're onboarding an intern. Rather than explaining for 30 minutes how to write a meeting summary, you show them 3 exemplary summaries and say "Do the same". That's exactly what few-shot prompting does.
Structure of a few-shot prompt
The structure is always the same: instruction → examples → actual question.
[General instruction describing the task]
Example 1:
Input: [example input 1]
Output: [expected output 1]
Example 2:
Input: [example input 2]
Output: [expected output 2]
Example 3:
Input: [example input 3]
Output: [expected output 3]
Now:
Input: [your actual question]
Output:
Concrete few-shot examples by use case
1. Support ticket classification (format + categorization)
Classify each ticket into a category and urgency level.
Strict format: Category: [X] | Urgency: [High/Medium/Low]
Ticket: "I can't log in since this morning"
Category: Authentication | Urgency: High
Ticket: "Is it possible to export my data as CSV?"
Category: Feature | Urgency: Low
Ticket: "The app crashes when I open the reports tab"
Category: Bug | Urgency: High
Ticket: "How do I change the interface language?"
Category: User support | Urgency: Low
Ticket: "Your competitor offers a built-in chat feature,
is this planned for your product?"
Category:
2. Product description generation (consistent tone + style)
Write an e-commerce product description in this exact style.
Each description: emoji + hook sentence + 3 features +
closing sentence. Less than 50 words total.
Product: Bluetooth headphones
Description: 🎧 Dive into crystal-clear sound. 30h battery life,
active noise cancellation, and ultra-light 180g design.
Your everyday audio companion, from the office to the commute.
Product: Urban backpack
Description: 🎒 The city-dweller's ally. 15" laptop compartment,
IPX4-certified waterproof fabric, and 12 organized pockets.
From the coffee shop to the boardroom, it follows you everywhere.
Product: Smart thermos
Description: 🌡️ Your drink, always at the right temperature.
LED temperature display, keeps hot 12h/cold 24h,
500ml stainless steel. The companion for busy mornings.
Product: Sport smartwatch
Description:
3. Structured extraction (precise JSON format)
Extract named entities in the following JSON format.
Required fields: company, product, location, date.
If a field is absent, use null.
Text: "Apple announced the iPhone 16 in Cupertino on September 9."
JSON: {"company": "Apple", "product": "iPhone 16",
"location": "Cupertino", "date": "September 9"}
Text: "Tesla will deliver the Cybertruck to European customers
from Berlin in March 2025."
JSON: {"company": "Tesla", "product": "Cybertruck",
"location": "Berlin", "date": "March 2025"}
Text: "Sanofi's new medication will be available
in pharmacies in the first quarter."
JSON: {"company": "Sanofi", "product": "new medication",
"location": null, "date": "first quarter"}
Text: "Google presented Gemini 3.1 at I/O in Mountain View
on May 14."
JSON:
4. LinkedIn hook writing (personal style)
Rewrite this raw information as an engaging LinkedIn hook.
Style: punchy first line (hook), then 3-4 lines
of context, then conclusion with a question.
Raw info: "I automated 40% of my tasks with AI"
LinkedIn post:
I eliminated 3 hours of repetitive work per day.
Not by hiring someone.
Not by working less.
By using ChatGPT + Zapier on 5 key workflows.
The result: 40% of my tasks run on autopilot.
What's the next task you're going to automate?
Raw info: "Our startup went from 0 to €100K MRR in 8 months"
LinkedIn post:
€100K in monthly recurring revenue.
8 months ago, it was €0.
No fundraising. No paid ads.
Just a product that solves a real problem + word of mouth.
The 3 decisions that changed everything ⬇️
What's YOUR strategy to reach PMF?
Raw info: "I changed careers at 40 to join tech"
LinkedIn post:
How many examples to provide?
| Number | Name | When to use | Token cost |
|---|---|---|---|
| 1 | one-shot | Simple format, familiar task | Low |
| 2-3 | standard few-shot | Good quality/cost balance for 80% of cases | Moderate |
| 4-5 | rich few-shot | Complex format, requires strong consistency | High |
| 6+ | many-shot | Rarely useful — risk of overloading context | Very high |
3 golden rules for choosing your examples
- →Diversity: your examples should cover the various cases of your task. For a 3-category classification, include at least one example of each.
- →Quality: mediocre examples produce mediocre results. Use your best real examples.
- →Representativeness: examples should resemble the real cases you'll process. Overly simple examples produce overly simple results.
Few-shot pitfalls to avoid
| Pitfall | What happens | Solution |
|---|---|---|
| Too similar examples | The model thinks all cases are identical | Vary examples (positive/negative, short/long) |
| Contradictory examples | The model is confused about the pattern | Check consistency between examples |
| Too many examples | Consumes tokens without improvement | 3 examples suffice in 80% of cases |
| Poorly formatted examples | The model reproduces format errors | Review your examples carefully |
| Example order | The model is biased by the last example | Put the most "normal" case last |
Zero-shot vs Few-shot: the decision tree
Zero-shot vs Few-shot — Selection guide
← Scroll horizontally →
Practical exercise: building your own few-shots
Duration: 20 minutes
- →Choose a recurring task in your work (email writing, classification, meeting summary)
- →Write 3 high-quality examples (real input + ideal output)
- →Test the few-shot prompt on a new real case
- →Compare with the same case in zero-shot — note the difference
- →Save this prompt in your template library (cf. section 10.2.8)
What is 'in-context learning' in LLMs?
How many few-shot examples are recommended for most use cases?