Few-Shot Prompting

How to teach AI new tasks by providing examples in your prompt.

7 min read
3 quiz questions

Few-shot prompting is one of the most powerful techniques in prompt engineering. Instead of just describing what you want, you show the AI examples. "Few-shot" means providing a few (typically 2-5) examples of input-output pairs before giving the actual task. The AI learns the pattern from your examples and applies it to new inputs.

This technique is particularly effective when your desired output has a specific format, tone, or logic that's hard to describe but easy to demonstrate. Just like teaching a new employee by showing them completed examples of the work, few-shot prompting teaches the AI through demonstration.

  1. Optional instruction describing the task
  2. Example 1: Input → Output
  3. Example 2: Input → Output
  4. (Optional) Example 3: Input → Output
  5. Actual input → (AI generates the output)

Few-Shot Classification

Teaches AI your classification categories through examples.

Classify each customer support message into a category.

Message: "I can't log into my account, it says password incorrect"
Category: Account Access

Message: "When will my order arrive? It's been 5 days"
Category: Shipping & Delivery

Message: "The product broke after two days of use"
Category: Product Quality

Message: "Can I get a refund for my last purchase?"
Category:

One-shot prompting uses a single example. It's faster and uses fewer tokens, but gives the AI less to learn from. Few-shot (2-5 examples) is more reliable because the AI can identify the pattern across multiple examples. Use one-shot for simple tasks and few-shot for anything nuanced.

The sweet spot is typically 3 examples. This gives the AI enough data to identify the pattern without wasting tokens. Add more examples only if 3 aren't producing consistent results.

Few-shot is especially powerful for matching a specific writing voice. Instead of trying to describe your brand voice (which is nearly impossible), just show 2-3 examples of writing in your voice and ask the AI to match it.

Style Matching via Few-Shot

Teaches AI your exact brand voice through example product descriptions.

Write product descriptions in our brand voice. Here are examples:

Product: Bamboo Water Bottle
Description: Ditch the plastic. Our bamboo bottle keeps drinks cold for 24 hours and looks good doing it. Sustainable sipping, no compromises.

Product: Recycled Tote Bag
Description: Made from 12 recycled bottles. Tough enough for groceries, cute enough for brunch. Your daily carry, minus the guilt.

Product: Solar Phone Charger
Description:

Prompt Templates

Few-Shot Data Extraction

Teaches AI your exact extraction format through examples.

Extract contact information from these messages.

Message: "Hey, reach me at [email protected] or call 555-0123"
Extracted: {"name": "John", "email": "[email protected]", "phone": "555-0123"}

Message: "This is Sarah from Acme Corp, my number is (555) 987-6543"
Extracted: {"name": "Sarah", "company": "Acme Corp", "phone": "555-987-6543"}

Message: "[YOUR MESSAGE]"
Extracted:

Few-Shot Summarization Style

Gets consistent one-sentence summaries by showing the exact style you want.

Summarize each article in exactly one sentence using this format:

Article: [long text about renewable energy growth]
Summary: Renewable energy installations grew 50% year-over-year, driven by solar panel cost reductions.

Article: [long text about remote work trends]
Summary: Remote work has plateaued at 28% of US workers, with hybrid models becoming the dominant pattern.

Article: [YOUR ARTICLE TEXT]
Summary:

Test Your Knowledge

Knowledge Check

1 / 3

What does "few-shot" mean in prompt engineering?

Key Takeaways

  • Few-shot prompting teaches AI by showing examples, not just describing the task
  • The typical structure: instruction → examples → actual input
  • Three examples is usually the sweet spot for consistency vs. token efficiency
  • Few-shot is especially powerful for matching tone, style, and custom formats
  • Use one-shot for simple tasks, few-shot for nuanced or pattern-dependent tasks