← All Techniques
📋

Few-Shot Prompting — Prompting Guide & Examples

Few-shot prompting provides the AI with 2-5 examples of the desired input-output pattern before asking it to handle a new case. The model learns the task format, style, and logic from these examples — no fine-tuning required.

How It Works

Include several input→output examples in your prompt, then present the new input. The model pattern-matches against your examples to produce consistent outputs. More examples generally improve consistency, but 3-5 usually suffice for most tasks.

When to Use

Use few-shot for classification tasks, format standardization, style matching, data extraction, and any task where you need consistent outputs that follow a specific pattern. Essential when zero-shot instructions produce inconsistent results.

Model-Specific Tips

ChatGPT / GPT-4

GPT-4 handles few-shot extremely well. Place examples in the user message or system prompt. 3-5 examples is the sweet spot for most tasks.

Claude

Claude is excellent at few-shot. Use XML tags to clearly delineate examples: <example>input→output</example>. Claude responds well to structured example formatting.

Gemini

Gemini supports few-shot natively. Provide examples in a clear format. Gemini 1.5 Pro's large context window allows many examples without truncation.

Pros & Cons

Pros

  • Easy to implement — just add examples
  • Produces highly consistent outputs
  • Works for any task you can demonstrate
  • No fine-tuning or training needed

Cons

  • Uses more tokens per request
  • Example quality directly limits output quality
  • Can overfit to example patterns
  • Selecting good examples requires thought

Example Prompts

Classify the sentiment: Text: 'This product changed my life!' Sentiment: Positive Text: 'Worst purchase ever, total waste.' Sentiment: Negative Text: 'It works okay, nothing special.' Sentiment: Neutral Text: 'I can't believe how fast shipping was!' Sentiment:

Extract structured data: Input: 'John Smith, CEO at Acme Corp, john@acme.com' Output: {name: 'John Smith', title: 'CEO', company: 'Acme Corp', email: 'john@acme.com'} Input: 'Sarah Lee, VP Marketing, TechStart Inc, sarah@techstart.io' Output:

Rewrite in brand voice: Before: 'Our software is good.' After: 'Our platform empowers teams to ship 10x faster.' Before: 'We have a lot of features.' After: 'Every feature is purpose-built to eliminate friction from your workflow.' Before: 'Try it today.' After:

FAQ

What is Few-Shot Prompting?
Few-shot prompting provides the AI with 2-5 examples of the desired input-output pattern before asking it to handle a new case. The model learns the task format, style, and logic from these examples — no fine-tuning required.
When should I use Few-Shot Prompting?
Use few-shot for classification tasks, format standardization, style matching, data extraction, and any task where you need consistent outputs that follow a specific pattern. Essential when zero-shot instructions produce inconsistent results.
How does Few-Shot Prompting work?
Include several input→output examples in your prompt, then present the new input. The model pattern-matches against your examples to produce consistent outputs. More examples generally improve consistency, but 3-5 usually suffice for most tasks.
Does Few-Shot Prompting work with ChatGPT?
GPT-4 handles few-shot extremely well. Place examples in the user message or system prompt. 3-5 examples is the sweet spot for most tasks.
Does Few-Shot Prompting work with Claude?
Claude is excellent at few-shot. Use XML tags to clearly delineate examples: <example>input→output</example>. Claude responds well to structured example formatting.