Skip to content
AgenticAIWiki
  1. Learn
  2. Part 2
  3. 12. Few-shot examples
  4. 12.2

Lesson 12.2 · 2 of 4 · 5 min read · Reviewed 24 Nov 2026

Choosing examples that cover edge cases

By the end, you can

  • Pick examples that cover the cases that matter.
  • Use examples to teach a decision boundary.

Examples teach by pattern, so the pattern you show is the one you get.

Cover the hard cases

Easy examples confirm what the model already does. The value is at the edges:

  • A review that’s mixed: “Great food, terrible service.”
  • Sarcasm: “Oh wonderful, it broke again.”
  • A ticket that looks like billing but is really a bug.

Each borderline example shows where the line falls.

Keep it balanced

If four of five examples are “positive”, the model learns that “positive” is the safe guess. Vary the labels and the inputs: short and long, formal and casual.

Use your failures

The best source of examples is your own error log. When the prompt gets a case wrong, the corrected case often makes the perfect new example. Then re-run your evalEval: A repeatable test that measures how well an AI system performs on a set of cases with defined success criteria. to check the fix didn’t break something else (15.3).

Key points

  • Choose examples that are varied and include hard and borderline cases, not just easy ones.
  • Balance the labels, or the model may lean towards the most common one.
  • Draw examples from real data, especially from cases the prompt got wrong.
Hands-on labRuns in the Playground

Balance a few-shot example set

Replace a lopsided example set with a balanced one that includes borderline cases.

You will have: A pick_balanced function and a before and after report of label counts and borderline cases.

Steps

  1. Run the starter and read the report for the current set: four billing, one bug.
  2. Fill in pick_balanced: two examples per label, borderline cases first.
  3. Rerun and compare the before and after counts.
  4. Read the chosen examples and check each borderline one teaches a real boundary.
  5. Add a borderline ticket of your own to the pool and see if it is picked.

Done when

  • Before prints billing 4, bug 1 with no borderline cases.
  • After prints two of each label.
  • At least three chosen examples are borderline.

Open in the Playground No API key needed.

Starter code (Python)
from collections import Counter

# A pool of labelled tickets. "borderline" marks cases that look like one label but are another.
POOL = [
    {"text": "Charged twice for March", "label": "billing", "borderline": False},
    {"text": "Invoice shows the wrong VAT number", "label": "billing", "borderline": False},
    {"text": "Refund has not arrived after 10 days", "label": "billing", "borderline": False},
    {"text": "Card declined at renewal", "label": "billing", "borderline": False},
    {"text": "Checkout button charges nothing and shows an error", "label": "bug", "borderline": True},
    {"text": "Export to CSV crashes on large files", "label": "bug", "borderline": False},
    {"text": "Price on the invoice page shows NaN", "label": "bug", "borderline": True},
    {"text": "How do I change my billing email?", "label": "how-to", "borderline": True},
    {"text": "How do I add a teammate?", "label": "how-to", "borderline": False},
]
CURRENT = POOL[:4] + POOL[5:6]   # four billing, one bug: the set from the lesson

def report(examples):
    counts = Counter(e["label"] for e in examples)
    return ", ".join(f"{k} {counts[k]}" for k in sorted(counts)), sum(e["borderline"] for e in examples)

def pick_balanced(pool, per_label=2):
    chosen = []
    # TODO: for each label (sorted), take per_label items from the pool,
    #       borderline cases first, then alphabetical by text.
    return chosen

labels, border = report(CURRENT)
print(f"before: {labels} | borderline {border}")
balanced = pick_balanced(POOL)
labels, border = report(balanced)
print(f"after: {labels} | borderline {border}")
for e in balanced:
    print(f"  [{e['label']}] {e['text']}" + ("  (borderline)" if e["borderline"] else ""))
Show a solution
from collections import Counter

# A pool of labelled tickets. "borderline" marks cases that look like one label but are another.
POOL = [
    {"text": "Charged twice for March", "label": "billing", "borderline": False},
    {"text": "Invoice shows the wrong VAT number", "label": "billing", "borderline": False},
    {"text": "Refund has not arrived after 10 days", "label": "billing", "borderline": False},
    {"text": "Card declined at renewal", "label": "billing", "borderline": False},
    {"text": "Checkout button charges nothing and shows an error", "label": "bug", "borderline": True},
    {"text": "Export to CSV crashes on large files", "label": "bug", "borderline": False},
    {"text": "Price on the invoice page shows NaN", "label": "bug", "borderline": True},
    {"text": "How do I change my billing email?", "label": "how-to", "borderline": True},
    {"text": "How do I add a teammate?", "label": "how-to", "borderline": False},
]
CURRENT = POOL[:4] + POOL[5:6]   # four billing, one bug: the set from the lesson

def report(examples):
    counts = Counter(e["label"] for e in examples)
    return ", ".join(f"{k} {counts[k]}" for k in sorted(counts)), sum(e["borderline"] for e in examples)

def pick_balanced(pool, per_label=2):
    chosen = []
    for label in sorted({e["label"] for e in pool}):
        items = [e for e in pool if e["label"] == label]
        items.sort(key=lambda e: (not e["borderline"], e["text"]))   # borderline cases first
        chosen.extend(items[:per_label])
    return chosen

labels, border = report(CURRENT)
print(f"before: {labels} | borderline {border}")
balanced = pick_balanced(POOL)
labels, border = report(balanced)
print(f"after: {labels} | borderline {border}")
for e in balanced:
    print(f"  [{e['label']}] {e['text']}" + ("  (borderline)" if e["borderline"] else ""))
Quick checkYour few-shot examples for a sentiment classifier are all clearly positive or clearly negative. What's missing?
How sure are you?
Pick an answer and how sure you are