Few-Shot Prompting
When a pattern is too complex to demonstrate with a single example, or when consistency across multiple outputs is critical, providing two or more examples inside the prompt significantly improves accuracy. This is the core idea behind Few-Shot Prompting.
The word "few" means a small number — typically two to five examples. These examples train the AI on the exact pattern to follow, without needing to retrain the entire model.
What is Few-Shot Prompting?
Few-Shot Prompting is the technique of providing multiple examples (usually two to five) within the prompt itself before presenting the actual task. Each example shows an input-output pair. The AI learns the pattern from these examples and applies the same logic to the new input.
Few-shot prompting is especially powerful for tasks that involve:
- Consistent tone and style across multiple outputs
- Complex or non-obvious classification rules
- Custom formats that are unique to a specific use case
- Tasks where the AI might produce varying results without clear guidance
Structure of a Few-Shot Prompt
A few-shot prompt follows this general structure:
- A brief description of the task (optional but helpful)
- Two or more input-output examples, clearly labeled
- The actual new input for which an output is needed
The more consistent and representative the examples are, the better the AI performs on the new input.
Few-Shot Prompt Examples
Example 1 — Categorizing Support Tickets
Prompt:
Classify each customer support ticket into one of these categories: Billing, Technical, Shipping, or General.
Ticket: "I was charged twice for the same order last week."
Category: Billing
Ticket: "The app crashes every time I try to upload a file."
Category: Technical
Ticket: "My package was supposed to arrive on Monday but it still hasn't shown up."
Category: Shipping
Now classify:
Ticket: "I can't log in to my account. The password reset email is not arriving."
Expected Output: Technical
Example 2 — Converting Casual Text to Professional Language
Prompt:
Rewrite each casual message as a professional workplace message.
Casual: "Hey, can we push the meeting to later today?"
Professional: "Could we reschedule today's meeting to a later time? Please let me know your availability."
Casual: "I totally forgot to send that report. My bad."
Professional: "I apologize for the oversight — the report was not sent as planned. I will send it shortly."
Now rewrite:
Casual: "This deadline is way too tight. There's no way we can get this done."
Expected Output: The current deadline presents a significant challenge for the team. We would like to discuss the possibility of a brief extension to ensure the quality of the deliverable.
Example 3 — Generating Menu Descriptions
Prompt:
Write a short, appetizing menu description for each dish. Keep it under 25 words. Focus on taste and texture.
Dish: Grilled Salmon
Description: Tender salmon fillet, grilled to perfection with a smoky herb crust — light, flaky, and bursting with natural flavour.
Dish: Mushroom Risotto
Description: Creamy Arborio rice slow-cooked with earthy mushrooms, finished with parmesan — rich, velvety, and deeply satisfying.
Now write for:
Dish: Mango Chicken Salad
Expected Output: Juicy grilled chicken tossed with ripe mango, crisp greens, and a zesty lime dressing — fresh, vibrant, and light.
Example 4 — Identifying Logical Errors
Prompt:
Identify the logical error in each statement and explain it in one sentence.
Statement: "Everyone who exercises regularly is healthy. John exercises every day. Therefore, John never gets sick."
Error: Regular exercise improves health but does not guarantee immunity from illness — the conclusion is overstated.
Statement: "Our best employee this year worked overtime every weekend. To get the best results, all employees should work overtime every weekend."
Error: Assuming that what worked for one person will work equally for everyone ignores individual differences and burnout risk.
Now identify the error in:
Statement: "Our new product launch received great reviews online. Therefore, all our future products will also receive great reviews."
Expected Output: Past success does not guarantee future outcomes — each product's reception depends on its own quality, market conditions, and customer expectations.
How Many Examples Should a Few-Shot Prompt Include?
The right number of examples depends on the complexity of the task:
| Task Complexity | Suggested Examples |
|---|---|
| Simple classification or labeling | 2–3 examples |
| Rewriting or tone transformation | 2–3 examples |
| Complex pattern with multiple variables | 3–5 examples |
| Tasks with many possible edge cases | 4–5 examples covering different scenarios |
More than five examples in a single prompt can make it too long and may reduce clarity. If more guidance is needed, consider using prompt chaining or templates — both covered in the Intermediate section.
Best Practices for Few-Shot Prompting
Keep Examples Diverse
If all examples show the same type of input, the AI may struggle with different kinds of inputs. Include examples that cover different cases within the task.
Keep Input-Output Pairs Consistent
Every example should follow the same structure — input first, then output. Inconsistent formatting confuses the AI about what it should replicate.
Use Clear Labels
Label each part clearly — "Input:", "Output:", "Sentence:", "Category:", etc. This prevents the AI from mixing up what is the example and what is the new task.
Keep Examples Realistic
Use examples that represent the kind of inputs the AI will actually encounter. Overly simple or unusual examples may not transfer well to real inputs.
Comparison — Zero-Shot vs One-Shot vs Few-Shot
| Feature | Zero-Shot | One-Shot | Few-Shot |
|---|---|---|---|
| Examples Provided | 0 | 1 | 2 or more |
| Setup Time | Minimal | Low | Moderate |
| Output Consistency | Variable | Good | High |
| Best For | Common tasks | Format-specific tasks | Complex or patterned tasks |
Key Takeaway
Few-Shot Prompting provides the AI with multiple input-output examples before the actual task. The examples teach the AI a specific pattern, tone, structure, or style. This technique is highly effective for tasks that require consistency, complex classification, or custom formatting. The ideal number of examples is typically two to five — enough to establish a clear pattern without making the prompt excessively long.
In the next topic, we will explore Writing Clear and Specific Prompts — the principles and habits that make every type of prompt more effective.
