Table of Contents

    Few-Shot

    Few-Shot
    Figure: Few-Shot

    PROMPT ENGINEERING

    Few-Shot Prompting

    Guide the AI with a few examples so it learns your pattern and imitates it.

    What Is Few-Shot Prompting?

    Few-shot prompting means giving the model 2 to 5 examples of the input-to-output pattern you want, right inside your prompt. Instead of relying only on instructions, the model studies your examples and imitates their style, format, and logic.

    This ability to learn from examples at the moment of the request — without any retraining — is called in-context learning. It dramatically improves consistency for structured or nuanced tasks where zero-shot alone falls short.

    In one line: Zero-shot tells the model what to do; few-shot shows it what "good" looks like.

    A Simple Analogy

    It's like training a new employee. Instead of only describing the task, you show them two or three finished samples. They quickly grasp the exact format and tone you expect — then apply it to the next item on their own.

    How Many Examples Should You Use?

    The number of examples — the "shots" — depends on how tricky the task is.

    1

    1-Shot

    A single demonstration.

    Best for quickly showing one format or tone.

    2

    2 to 3-Shot

    The sweet spot for most tasks.

    Ideal for classification, extraction, and formatting.

    3

    4 to 5-Shot

    More coverage for complex cases.

    Use for nuanced tasks with edge cases or multiple categories.

    RULE OF THUMB
    Clean examples > Many examples

    The Key Concepts

    In-context learning: the model detects the pattern from your examples on the fly — no fine-tuning or training required.
    Quality over quantity: three clean, representative examples beat ten noisy ones.
    Consistency of format: keep every example in the exact structure you want the final answer to follow.

    Example: A 3-Shot Classification Prompt

    Here is a reusable few-shot prompt that classifies customer feedback into three categories. Notice how each example follows the identical format:

    Classify each customer review as: Bug, Feature Request, or Praise.
    
    Review: "The app crashes every time I open the settings page."
    Category: Bug
    
    Review: "It would be great if you added a dark mode option."
    Category: Feature Request
    
    Review: "Absolutely love the new dashboard, it's so fast!"
    Category: Praise
    
    Review: "I can't log in after the latest update."
    Category:

    The model sees the three demonstrations, learns the mapping, and completes the final Category: correctly as Bug.

    Few-Shot with Structured Output

    Few-shot is especially powerful when you need consistent, machine-readable results. The examples lock in the exact JSON shape:

    [
      {
        "input": "Order #123 arrived broken.",
        "output": { "intent": "complaint", "priority": "high" }
      },
      {
        "input": "When will my package ship?",
        "output": { "intent": "question", "priority": "medium" }
      },
      {
        "input": "Thanks, the replacement works perfectly!",
        "output": { "intent": "praise", "priority": "low" }
      }
    ]

    Best Practices for Few-Shot Prompting

    • Prioritise quality over quantity — a few clean examples go a long way
    • Keep your examples diverse to cover different real-world cases
    • Use the identical format and structure for every example
    • Balance your categories so the model doesn't develop a bias
    • Place the new input in the same layout as your examples

    Zero-Shot vs. Few-Shot at a Glance

    Aspect Zero-Shot Few-Shot
    Examples given None 2–5 examples
    Consistency Good on simple tasks Higher on tricky tasks
    Best for Common, simple tasks Nuanced or structured tasks
    Token cost Low Higher (examples add length)
    Effort to write Fastest Moderate

    Common Pitfalls to Watch Out For

    Pitfall 1 — Biased examples If all your examples share a hidden bias (for instance, every sample is positive sentiment), the model will echo that bias on new inputs.
    Pitfall 2 — Too many examples Overloading the prompt wastes tokens, increases cost, and can even dilute the signal. Stop once quality plateaus.
    Pitfall 3 — Inconsistent format If your examples don't share the same structure, the model gets confused about what the output should look like.
    Fix — Curate, don't accumulate Choose a small, balanced, consistently-formatted set of examples that represent the real variety of your inputs.

    A Note on the "Shots"

    The "shot" count refers to the number of labelled examples \( n \) included in the prompt. Few-shot is simply the range where a small number of examples is supplied:

    $$ \text{Few-shot} \;\Longleftrightarrow\; 1 \le n \le 5 $$

    Key Takeaway

    Few-shot prompting is your go-to when zero-shot isn't consistent enough. Show the model 2–5 clean, diverse, identically-formatted examples, and it will faithfully imitate the pattern on new inputs.