Zero-Shot, Few-Shot & Worked Examples

Use input/output examples to lock in a pattern the model should follow, and know when zero-shot is enough.

TL;DR

  1. Zero-shot asks with no examples; few-shot shows one to a few input/output pairs to lock in a pattern.
  2. Reach for examples when the shape, naming, or style is easier to show than to describe.
  3. Two or three well-chosen examples usually beat a long paragraph of rules.

Zero-Shot

    What It Is

    Ask directly with no examples; rely on the model's general knowledge.

    "Write a Python function that checks if
    a string is a palindrome."
    When To Use

    Common, well-defined tasks where there is one obvious right shape.

    Standard algorithms, simple utilities,
    idiomatic one-liners.
    Strengthen It

    Even without examples, pin the signature and constraints.

    "...signature isPalindrome(s: str) -> bool,
    ignore case and spaces."

Few-Shot

    What It Is

    Provide a few input/output pairs, then ask for the next output.

    format(1500)   -> "$1,500.00"
    format(0)      -> "$0.00"
    format(-42.5)  -> "-$42.50"
    format(99999)  -> ?
    When To Use

    When exact shape, naming, or formatting is specific and easier shown than told.

    Custom output shapes, DSLs, label
    conventions, structured logs.
    Cover Edge Cases

    Include zero, negative, or empty examples so the model copies that handling.

    Show format(0) and format(-42.5),
    not just the happy path.

Choosing

    Describable? Zero-Shot

    If a sentence fully captures the task, skip examples and save context.

    "Slugify a string: lowercase,
    spaces to hyphens." -> no examples needed
    Show-Me? Few-Shot

    If the pattern has quirks, two examples teach it faster than a paragraph.

    Quirky mapping -> show 2-3 pairs
    Mix Them

    Describe the task, then add a couple of examples for the fiddly parts.

    Rules + 2 examples of the edge cases.

Pitfalls

    Inconsistent Examples

    One example that breaks the pattern teaches the wrong rule.

    Keep casing, spacing, and shape
    identical across all examples.
    Overfitting

    The model may copy incidental details of your samples, not the intent.

    Vary the sample values so it learns
    the rule, not the specific numbers.
    Examples vs Rules

    When examples contradict instructions, examples often win; keep them aligned.

    Align the examples with the stated rule.

Tips

  1. Make examples cover the tricky cases (empty input, nulls) so the model copies the handling you want.
  2. Keep examples consistent; one off-pattern example teaches the model the wrong rule.

Warnings

  1. Too many examples waste context and can make the model overfit to surface details of your samples.
  2. If examples disagree with your written instructions, the model may follow the examples instead.

In Practice

FAQ