Task: get the AI to classify user feedback into three categories — "feature request", "bug report", or "usage question".
Level 1: Design high-quality examplesDesign 3 few-shot examples that cover different cases and keep a consistent format.
Learning goals:
- Understand the difference between zero-shot, one-shot, and few-shot
- Learn to use 2-5 examples to make the AI grasp a pattern
- Master the principles for choosing high-quality examples
Prerequisites: << Lesson 2: The Basic Structure of a Prompt | Next: Lesson 4 >>
You want the AI to output data in a specific format — say, "pull the key facts out of this article and return them as JSON." You spend a while in the prompt spelling out field names, data types, nesting... and the AI still hands back something shaped differently from what you pictured.
Try another way. Stop describing the format and show the AI 2-3 clean examples instead. It reads them, sees exactly what you want, and gets the format right on the first try. That's the power of few-shot learning: an example is clearer than a paragraph of description1.
Few-shot learning is a prompt technique that guides the AI toward the pattern you want by placing a small number of examples (usually 2-5) in the prompt2 1. The AI learns the input-output relationship, the format, and the style from those examples, then applies it to a new input.
Three ways to compare:
Zero-shot prompt:
The AI might return:
With no examples, the AI can only lean on its own judgment for the edge cases.
Few-shot prompt:
After seeing the examples, the AI understands:
So it returns "neutral", because this review matches the pattern of the third example.
Few-shot learning taps into a large language model's in-context learning ability2. The model isn't retrained; it just sees a few examples in the current conversation, infers the rule, and applies it.
The model picks up three kinds of information from the examples:
A key finding: research shows that the format and diversity of the examples matter more than whether every example is correct2. Even if a few labels in the examples are wrong, the AI can still learn a useful pattern, as long as the format is consistent and the examples cover different kinds of input.
You can't just throw in any few examples. The quality of your examples directly shapes the AI's output1.
Start with 2, and add a third or fourth only if the results aren't good enough1.
Your examples should cover the different kinds of input the task might see — that is, example diversity2.
Examples that lack diversity:
Every example is a phone. The AI has never seen another kind of electronic product, so it may not know how to handle one.
Examples with diversity:
This covers different product categories, so the AI can learn a more general classification logic.
Format consistency is the key to a successful few-shot prompt2.
Inconsistent format:
The format is all over the place, so the AI doesn't know whether to output "positive", "positive sentiment", or something else.
Consistent format:
Clean and uniform, so the AI knows the output should be a single adjective.
If the task has gray areas, put them in the examples1.
Scenario: judging whether a code comment is useful
Only the obvious examples:
With edge cases included:
Examples 3 and 4 help the AI see the boundary: not every comment that "explains what the code does" is useful. What matters is whether the code already expresses its intent clearly on its own.
The most common task here is pulling structured data out of unstructured text.
Zero-shot version (unreliable):
The AI might return all sorts of formats:
or
Field names, format, and units are all inconsistent.
Few-shot version (stable format):
The examples cover three salary units (per year, per month, per hour) and three location types (city, city plus area, remote), so the AI learns:
Give just one example and the AI sees a single instance, not a rule.
Fix: at least 2, ideally 3.
An arrow → here, a colon : there, multiple lines somewhere else.
Fix: pick one format and follow it strictly in every example.
Real data has noise, ambiguity, and gaps. If the examples only show the ideal case, the AI stalls the moment it hits an edge case.
Fix: at least one example should include an edge case (a missing field, an ambiguous phrasing).
Past 5 examples the payoff is tiny, and you burn extra tokens and lengthen the response.
Fix: start with 2-3, add more only if needed. You rarely need more than 5.
Few-shot fits these situations best:
When it doesn't fit:
A rule of thumb: if you could show a human colleague 2-3 examples and they'd understand what to do, few-shot is a good fit.
Few-shot learning uses 2-5 examples to make the AI grasp the pattern you want, which is clearer than describing it in words. High-quality examples are: moderate in number (2-5), representative and diverse, identical in format, and inclusive of edge cases.
Few-shot fits format conversion, classification, and style imitation best. When designing examples, start with 2, make sure they cover different kinds of input, and use the same format across all of them.
Next lesson covers chain-of-thought — how to make the AI show its reasoning steps and improve accuracy on complex tasks.
Next lesson Chain-of-Thought: Making AI Show Its Reasoning >>
Few-Shot Prompting Guide — https://www.prompthub.us/blog/the-few-shot-prompting-guide ↩ ↩2 ↩3 ↩4 ↩5
Prompt Engineering Guide - Few-Shot Prompting — https://www.promptingguide.ai/techniques/fewshot ↩ ↩2 ↩3 ↩4 ↩5 ↩6
Zero-shot Learning - Wikipedia — https://en.wikipedia.org/wiki/Zero-shot_learning ↩
Design 3 few-shot examples that cover different cases and keep a consistent format.
Problem: the AI's output is unstable — sometimes the field names come out in another language, sometimes the pros are adjectives ("good") instead of concrete points ("quality").
Classify the user review below as "positive", "negative", or "neutral".
Review: This product works fine, but it's a little expensive.Classification:Classify user reviews as "positive", "negative", or "neutral".
Examples:
Review: The build quality is great, I'm really happy with it.Classification: positive
Review: Completely unusable, a waste of money.Classification: negative
Review: The features are okay, but customer support is slow.Classification: neutral
Now classify this review:
Review: This product works fine, but it's a little expensive.Classification:Example 1: iPhone 15 Pro → phoneExample 2: iPhone 14 → phoneExample 3: iPhone 13 → phone
Now classify: MacBook ProExample 1: iPhone 15 Pro → phoneExample 2: MacBook Air → laptopExample 3: AirPods Pro → headphones
Now classify: iPad ProExample 1:Input: What a nice dayOutput: positive
Example 2:"This movie was so boring" --> negative sentiment
Example 3: it's okay → neutralExample 1:Input: What a nice dayOutput: positive
Example 2:Input: This movie was so boringOutput: negative
Example 3:Input: it's okayOutput: neutralExample 1:Code: x = x + 1 # add 1Verdict: useless (the comment just repeats the code)
Example 2:Code: result = calculate_tax(income, deductions) # compute tax owedVerdict: useful (explains the business meaning)Example 1:Code: x = x + 1 # add 1Verdict: useless (the comment just repeats the code)
Example 2:Code: result = calculate_tax(income, deductions) # compute tax owedVerdict: useful (explains the business meaning)
Example 3:Code: time.sleep(2) # wait for the API rate limit to resetVerdict: useful (explains why we wait, which isn't obvious)
Example 4:Code: users = users.filter(active=True) # filter active usersVerdict: useless (the method name already makes this clear)From the job posting below, extract: job title, salary range, location,experience required. Return it as JSON.
Job posting: We're hiring a senior Python developer, based in New York,3-5 years of experience, $140-160k per year.{"title": "Python developer", "pay": "140-160k", ...}
{"job": "senior Python developer", "salary": "$140-160k/yr", ...}
Extract the key fields from a job posting and return them in the JSONformat below.
Example 1:Input: Hiring a frontend engineer, San Francisco, 2-3 years experience,$120-150k per yearOutput:{ "position": "frontend engineer", "location": "San Francisco", "experience": "2-3 years", "salary": "$120-150k/year"}
Example 2:Input: Urgent: Java backend, Austin (downtown), 5+ years required,$8-10k per monthOutput:{ "position": "Java backend", "location": "Austin (downtown)", "experience": "5+ years", "salary": "$8-10k/month"}
Example 3:Input: Data analyst, remote, experience open, $60-80 per hourOutput:{ "position": "data analyst", "location": "remote", "experience": "open", "salary": "$60-80/hour"}
Now handle this one:Input: We're hiring a senior Python developer, based in New York, 3-5 yearsof experience, $140-160k per year.Output:Extract the pros and cons from a product review, output JSON.
Examples:"decent quality" -> {"pros": ["quality"], "cons": []}"too expensive, and slow shipping" -> {"pros": [], "cons": ["expensive", "slow delivery"]}
Now handle: [review text]