---
title: "Few-Shot Prompting"
description: "Getting better results with examples"
canonical_url: "https://meingpt.com/en/docs/prompting/11-techniques-few-shot"
language: en
---

# Few-Shot Prompting

Few-Shot Prompting uses several examples to show the AI what format or type of response you expect. This technique significantly improves results, especially for specific or complex tasks.

## How does Few-Shot work?

You provide 2-5 examples before your actual request. The AI learns from these patterns and applies them to your task.

### Basic Structure
```
Example 1: [Input] → [Output]
Example 2: [Input] → [Output]
Example 3: [Input] → [Output]
Your request: [Input] → ?
```

## Practical Applications

### Sentiment Analysis
```
Text: "The service was fast and friendly"
Sentiment: Positive

Text: "The product arrived damaged"
Sentiment: Negative

Text: "The delivery was on time"
Sentiment: Neutral

Text: "I'm thrilled with the quality and price"
Sentiment:
```
**Output**: Positive

### Data Formatting
```
Input: Max Mustermann, Berlin, 35 years
Output: {"name": "Max Mustermann", "city": "Berlin", "age": 35}

Input: Anna Schmidt, Munich, 28 years
Output: {"name": "Anna Schmidt", "city": "Munich", "age": 28}

Input: Tom Weber, Hamburg, 42 years
Output:
```
**Output**: `{"name": "Tom Weber", "city": "Hamburg", "age": 42}`

### Email Categorization
```
Email: "When will my order be delivered?"
Category: Delivery inquiry

Email: "I want to cancel my order"
Category: Cancellation

Email: "The product has a defect"
Category: Complaint

Email: "Do you have this product in blue?"
Category:
```
**Output**: Product inquiry

## Advantages of Few-Shot

### Precision

Exact control over output format

### Consistency

Consistent results across multiple requests

### Flexibility

Adaptable to specific company requirements

## Best Practices for Few-Shot

### 1. Quality of Examples
```
✅ Good examples:
- Diverse and representative
- Clearly structured
- Error-free

❌ Bad examples:
- Too similar to each other
- Inconsistent format
- Contains errors
```

### 2. Number of Examples
- **2-3 examples**: For simple tasks
- **3-5 examples**: For more complex patterns
- **5+ examples**: Rarely necessary, can be counterproductive

### 3. Order
```
Tip: Arrange examples from simple to complex
1. Clear-cut case
2. Typical case
3. Edge case
```

## Advanced Techniques

### Negative Examples
Show what is NOT desired:
```
Correct: "Dear Mrs. Schmidt,"
Incorrect: "Hey Schmidt,"

Correct: "Best regards"
Incorrect: "BR"
```

### Few-Shot with Explanations
```
Text: "The food was cold"
Sentiment: Negative
Explanation: Cold food indicates poor quality

Text: "The price is fair"
Sentiment: Neutral
Explanation: "Fair" is neither particularly positive nor negative
```

### Chain-of-Thought in Few-Shot
```
Question: "If Peter has 3 apples and buys 2 more, how many does he have?"
Thought process: Peter starts with 3 apples. He buys 2 more. 3 + 2 = 5
Answer: 5 apples

Question: "Maria has 10€ and spends 4€. How much is left?"
Thought process: Maria starts with 10€. She spends 4€. 10 - 4 = 6
Answer: 6€
```

## Avoiding Common Mistakes

**Avoid these mistakes:**
- Too many examples (confuses the AI)
- Inconsistent formatting
- Examples that don't match the task
- Overcomplicated patterns

## When to Use Few-Shot

✅ **Ideal for:**
- Specific formatting requirements
- Company-specific classifications
- Consistent outputs across multiple requests
- New or unusual tasks

❌ **Less suitable for:**
- Simple, standardized tasks
- When you don't have good examples
- Very creative or open-ended tasks

## Practical Template

```
# Few-Shot Template for [Your Task]

## Example 1
Input: [Sample input]
Output: [Desired output]

## Example 2
Input: [Sample input]
Output: [Desired output]

## Example 3
Input: [Sample input]
Output: [Desired output]

## Your Request
Input: [Your actual input]
Output:
```

**Pro Tip**: Save successful Few-Shot prompts as templates for recurring tasks!

## Exercise

Create a Few-Shot prompt for:
1. Product descriptions in your company style
2. Categorization of customer inquiries
3. Converting technical language into simple language

**Next Step**: Discover Chain-of-Thought Prompting for complex thinking tasks.
