Skip to content
AgenticAIWiki
  1. Learn
  2. Part 13
  3. 67. Observability and tracing
  4. 67.4

Lesson 67.4 · 4 of 9 · 4 min read · Reviewed 24 Nov 2026

Online evals and drift detection

By the end, you can

  • Run evals on live traffic.
  • Detect drift in inputs and outputs.

Part 3 covers evalsEval: A repeatable test that measures how well an AI system performs on a set of cases with defined success criteria. you run before shipping. Production needs a second kind: evals that run on what users actually send.

Online signals

Signal Cost Notes
Thumbs up or down Free Sparse and biased toward unhappy users
Retry, rephrase or abandon Free Strong hint the answer missed
Escalation to a person Free Clear failure signal for support bots
Code checks on output Cheap Schema valid, citations present, no banned phrases
Model grader on a sample Moderate Score 1 to 5% of runs against a rubric
Human review of a sample Expensive Calibrates the model grader

Drift

  • Input drift: users start asking about a new product, in a new language, or with longer documents.
  • Output drift: answers get longer, refusals rise, or tool useTool use: Letting a model call functions you define, by returning a structured request your code executes. patterns change after a prompt or model update.

Track simple distributions over time: input length, topic labels, language, refusal rate, steps per run. A sudden or steady shift is a cue to look at examples.

Close the loop

When online signals find a new failure, copy real (redactedRedaction: Removing or masking sensitive data, such as PII or secrets, before it is stored, logged or sent.) examples into the offline test set. That way the next release is tested on the problem you just found.

Key points

  • Offline evals test known cases; online evals score a sample of real traffic as it happens.
  • Use cheap signals (thumbs down, retries, escalations) plus model or code graders on sampled runs.
  • Drift is a change over time in what users send or how the system answers; watch for it and refresh your test sets.
Hands-on labRuns in the Playground

Flag drift in weekly traffic

Spot input and output drift by comparing live weekly numbers with a baseline.

You will have: A drift checker that prints which weeks drifted and why.

Steps

  1. Run the starter: every week prints ok.
  2. Flag weeks whose average input length moved more than 30%.
  3. Flag refusal rates above twice the baseline.
  4. Flag topics that were absent in the baseline and now pass 10%.
  5. Decide which flagged examples you would copy into the offline test set.

Done when

  • Week 4 stays ok: the new topic is still small.
  • Week 5 flags input length and the new 'warranty' topic.
  • Week 6 also flags refusals.

Open in the Playground No API key needed.

Starter code (Python)
# Detect input and output drift by comparing each week with a baseline.
WEEKS = [
    {"week": 1, "input_tokens": 410, "refusals": 0.020, "topics": {"billing": 0.55, "shipping": 0.45}},
    {"week": 2, "input_tokens": 395, "refusals": 0.022, "topics": {"billing": 0.50, "shipping": 0.50}},
    {"week": 3, "input_tokens": 420, "refusals": 0.019, "topics": {"billing": 0.52, "shipping": 0.48}},
    {"week": 4, "input_tokens": 430, "refusals": 0.021, "topics": {"billing": 0.50, "shipping": 0.46, "warranty": 0.04}},
    {"week": 5, "input_tokens": 610, "refusals": 0.024, "topics": {"billing": 0.40, "shipping": 0.40, "warranty": 0.20}},
    {"week": 6, "input_tokens": 700, "refusals": 0.051, "topics": {"billing": 0.35, "shipping": 0.35, "warranty": 0.30}},
]
BASELINE = WEEKS[:3]
LENGTH_CHANGE = 0.30      # flag a 30% change in average input length
REFUSAL_FACTOR = 2.0      # flag refusals at twice the baseline rate
NEW_TOPIC_SHARE = 0.10    # flag a topic unseen in the baseline once it passes 10%


def baseline():
    n = len(BASELINE)
    known = set().union(*(w["topics"] for w in BASELINE))
    return sum(w["input_tokens"] for w in BASELINE) / n, sum(w["refusals"] for w in BASELINE) / n, known


def check(week, base_len, base_ref, known):
    flags = []
    # TODO: flag input length that changed by more than LENGTH_CHANGE versus base_len
    # TODO: flag a refusal rate above base_ref * REFUSAL_FACTOR
    # TODO: flag any topic not in `known` whose share is above NEW_TOPIC_SHARE
    return flags


base_len, base_ref, known = baseline()
print(f"baseline: {base_len:.0f} input tokens, refusals {base_ref:.1%}")
for w in WEEKS[3:]:
    flags = check(w, base_len, base_ref, known)
    print(f"week {w['week']}: " + ("drift: " + "; ".join(flags) if flags else "ok"))
Show a solution
# Detect input and output drift by comparing each week with a baseline.
WEEKS = [
    {"week": 1, "input_tokens": 410, "refusals": 0.020, "topics": {"billing": 0.55, "shipping": 0.45}},
    {"week": 2, "input_tokens": 395, "refusals": 0.022, "topics": {"billing": 0.50, "shipping": 0.50}},
    {"week": 3, "input_tokens": 420, "refusals": 0.019, "topics": {"billing": 0.52, "shipping": 0.48}},
    {"week": 4, "input_tokens": 430, "refusals": 0.021, "topics": {"billing": 0.50, "shipping": 0.46, "warranty": 0.04}},
    {"week": 5, "input_tokens": 610, "refusals": 0.024, "topics": {"billing": 0.40, "shipping": 0.40, "warranty": 0.20}},
    {"week": 6, "input_tokens": 700, "refusals": 0.051, "topics": {"billing": 0.35, "shipping": 0.35, "warranty": 0.30}},
]
BASELINE = WEEKS[:3]
LENGTH_CHANGE = 0.30      # flag a 30% change in average input length
REFUSAL_FACTOR = 2.0      # flag refusals at twice the baseline rate
NEW_TOPIC_SHARE = 0.10    # flag a topic unseen in the baseline once it passes 10%


def baseline():
    n = len(BASELINE)
    known = set().union(*(w["topics"] for w in BASELINE))
    return sum(w["input_tokens"] for w in BASELINE) / n, sum(w["refusals"] for w in BASELINE) / n, known


def check(week, base_len, base_ref, known):
    flags = []
    change = week["input_tokens"] / base_len - 1
    if abs(change) > LENGTH_CHANGE:
        flags.append(f"input length {change:+.0%}")
    if week["refusals"] > base_ref * REFUSAL_FACTOR:
        flags.append(f"refusals {week['refusals']:.1%}")
    for topic, share in week["topics"].items():
        if topic not in known and share > NEW_TOPIC_SHARE:
            flags.append(f"new topic '{topic}' at {share:.0%}")
    return flags


base_len, base_ref, known = baseline()
print(f"baseline: {base_len:.0f} input tokens, refusals {base_ref:.1%}")
for w in WEEKS[3:]:
    flags = check(w, base_len, base_ref, known)
    print(f"week {w['week']}: " + ("drift: " + "; ".join(flags) if flags else "ok"))
Quick checkOffline evals still pass, but complaints are rising. What is a likely cause to check?
How sure are you?
Pick an answer and how sure you are