Course contents

16. AI System Design Lesson 10 of 10

AI Observability and Evaluation

Trace LLM calls with prompts, tokens and versions, build offline eval sets, use LLM judges carefully, and catch regressions when a model changes.

16 minAdvanced9 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • A wrong answer is a 200 with normal latency: quality needs its own signals.
  • Trace each request with retrieval, model, prompt version, tokens and timings, linked to user feedback.
  • A versioned golden set with deterministic checks and rubric grading turns “seems better” into a number.
  • LLM judges are biased and noisy: calibrate against humans, swap order, and treat small differences as noise.
  • Gate model and prompt changes on evals, then canary them and compare by version.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

What it is

AI observability is the practice of recording what LLM-based features do in production, request by request: inputs, retrieved context, model and prompt versions, outputs, tokens, timings and user feedback. AI evaluation is the practice of measuring answer quality systematically: offline, on a fixed set of cases before a change ships, and online, on samples of live traffic. Together they answer two questions ordinary monitoring cannot: why did it say that? and is this version better than the last one?

Why it exists

LLM features fail in ways that do not show up as errors. A hallucinated discount code, an outdated policy, a broken output format or a refusal to answer a legitimate question is still an HTTP 200 with normal latency, as the simulation's green dashboard shows. Outputs are non-deterministic, depend on prompts, retrieved data and model versions that all change independently, and providers update models over time. Without traces you can't explain a bad answer; without evals you can't tell whether a change helped or hurt.

How it works

Tracing. Each request becomes a trace with spans for each step: retrieval (query, returned chunks and scores), each model call (model and version, prompt template version, parameters, input/output/cached token counts, time to first token, total time, finish reason), tool calls for agents, and the final output. User feedback (explicit ratings, implicit signals such as retries, copies or escalation) is attached by trace id. OpenTelemetry's generative AI semantic conventions define common attribute names (gen_ai.*); they are still evolving, so pin the version you emit. Export asynchronously so tracing never slows requests.

Privacy. Prompts and outputs often contain personal or confidential data. Decide what content to capture (all, sampled, or metadata only), redact identifiers, restrict access, and set retention. Many teams capture full content only for sampled or flagged traces.

Online metrics. Per route and per version: latency (time to first token and total), tokens and cost per request, error and refusal rates, feedback rates, retrieval coverage, and sampled quality scores. Compare by version and by segment; averages hide regressions in small but important groups.

Offline evaluation. A versioned dataset of representative cases: real questions (anonymised), with what a good answer must contain or must not contain, plus hard cases and every past production failure. An eval runner executes the pipeline on each case and grades with, in order of preference: deterministic checks (schema validity, required citation, exact facts, forbidden content), reference-based comparisons, and rubric-based grading by a judge model or humans. The output is a score per version with per-case results, so you can see which cases changed.

LLM-as-judge. A model grades outputs against a rubric, or picks the better of two answers. It scales where human review can't, but it has known biases: position (favouring the first answer in pairwise comparisons), verbosity (favouring longer answers), self-preference (favouring its own style or model family), and run-to-run inconsistency. Mitigations: specific rubrics with binary criteria, swapping order and discarding inconsistent verdicts, a pinned judge model and prompt, and regular measurement of agreement with human labels.

Uncertainty. Eval scores are estimates. With n cases and pass rate p, the standard error is about √(p(1−p)/n): for 200 cases at 85%, roughly ±5 points at 95% confidence. Compare versions on the same cases (paired), look at which cases flipped, and don't celebrate a two-point gain on a small set.

Regression gates and rollout. Run the eval set in CI for every change to the model, prompts, retrieval configuration, tools or judge. Block changes that drop beyond the noise margin or fail critical cases. Then roll out like any risky deploy: canary a small share, tag traces with versions, compare online metrics, and keep rollback a configuration change (an LLM gateway or router makes this easy).

When to use it

  • Any LLM feature that users depend on: from the first production release, not after the first incident.
  • Before changing models, prompts, chunking, embeddings or retrieval parameters.
  • Agents, where a single request has many steps and failures are hard to reconstruct without traces.

When not to

  • Heavy evaluation infrastructure for a throwaway prototype: a spreadsheet of 30 cases and manual review is enough to start.
  • Full content capture where regulation or contracts forbid storing prompts: capture metadata and sampled, consented content instead.
  • LLM judges for criteria that code can check exactly (format, presence of a citation, numeric correctness).

Trade-offs

Choice You gain You pay
Capturing full prompts and outputs Explainable failures, eval data from production Storage, privacy risk, access control
LLM judge instead of human review Scale and speed Bias and noise; needs calibration
Larger eval set Detects smaller regressions Cost and time per run; curation effort
Strict CI gate Fewer silent regressions Slower iteration; false blocks from noisy scores
Online sampling rate More quality signal Judge cost on live traffic

Alternatives

  • Human review only: highest quality labels, doesn't scale; best used to calibrate automated graders.
  • A/B tests on business metrics (resolution rate, conversion): the ground truth that matters, but slow and confounded.
  • Vendor or community benchmarks: say little about your data and your prompts; never a substitute for your own eval set.

Failure modes

  • Silent quality regressions after a model update, prompt edit or document change, invisible in latency and errors.
  • Overfitting to the eval set: prompts tuned until the score rises while real traffic gets worse. Refresh cases from production and hold some out.
  • Stale eval sets that no longer reflect what users ask.
  • Judge drift: the judge model changes and all scores shift. Pin it and re-calibrate when you must change it.
  • Leaky traces: personal data copied into observability tools with broad access.
  • Metric blindness by aggregation: an average that hides a severe regression in one language or customer segment.

In production

Instrument the pipeline once, centrally (an SDK wrapper or the LLM gateway), with model, prompt and retrieval versions on every span. Keep prompts, rubrics and eval datasets in version control and run evals in CI. Build dashboards by version and segment, alert on feedback-rate and cost-per-request changes as well as latency and errors, and run a judge on a small sample of live traffic. Review a handful of real traces every week; the patterns you find become new eval cases. Treat a provider's model update like a dependency upgrade: pin versions where you can, and evaluate before moving.

Common misconceptions

  • "No errors means it works." A wrong answer is a successful response.
  • "The judge's score is the truth." It is another model's opinion, with measurable biases.
  • "One good eval run proves a change is better." Small differences on small sets are noise; look at per-case changes.
  • "Benchmarks tell us which model to use." They tell you about the benchmark. Your eval set tells you about your product.
  • "Observability means logging prompts." It means structured traces with versions, tokens, timings and feedback that you can query and compare.

Interview angle

For any LLM system design, add an observability and evaluation section unprompted: what each trace contains, how personal data is handled, which online metrics and alerts you'd set, how the golden set is built and grown, how judges are calibrated, and how a model change is gated and rolled out. Quantitative awareness stands out: "200 cases gives about ±5 points, so we compare paired results and only block on drops beyond that, or on any critical case failing".

Model assumptions

The simulation covers only the serving path, as a simplified queueing model: a RAG app (10 ms of work) reads a retriever modelled as a database (32 connections, 40 ms per read) and calls a model through a router using smooth weighted round robin. Model v1 has 32 concurrent slots and a 1.2 s mean call time; Model v2 takes 2.0 s as first rolled out (longer answers) and 1.5 s after its prompt is fixed (lognormal, cv 0.5). The engine measures throughput, latency and errors and has no notion of answer quality. Tracing, feedback, eval runs and the judge model are scripted illustrations, and every quality score shown (86%, 78%, 85%, groundedness 0.82) is illustrative. Arrivals are Poisson; network hops are fixed. Numbers show behaviour and orders of magnitude only.

The lesson as textEvery step of the simulation, written out.
  1. 1. Every dashboard is green

    A RAG assistant answers 8 questions per second: it retrieves documents, then calls Model v1. The simulation shows what an ordinary dashboard shows: throughput steady, zero errors, P95 a little over 2 s.

    Meanwhile support tickets say the assistant cites the wrong policy and invents a discount code. A wrong answer is an HTTP 200 with a normal latency. Request metrics measure whether the system answered, not whether the answer was any good.

    Scene: Users send 8 questions per second to a RAG app that queries a retriever and Model v1. No request fails and P95 is a little over 2 s, while users report wrong answers.

    Key idea: For LLM features, “up and fast” says nothing about “right”: quality needs its own signals.

  2. 2. One trace per request, one span per step

    Each request now produces a trace: a span for retrieval (which chunks, their scores, 40 ms), a span for the model call (model and version, prompt template version, input and output tokens, time to first token, total time, finish reason) and the final answer. When the user clicks thumbs-down, that feedback is attached to the same trace id. Spans are exported asynchronously to a collector, off the request path.

    OpenTelemetry has semantic conventions for generative AI (gen_ai.* attributes such as the model and token counts); they are still evolving, but using them keeps traces portable. Prompts and answers can contain personal data: capture them deliberately, redact, restrict access and set retention.

    Scene: A scripted request goes through the retriever and Model v1 and back to the user; the user sends feedback, and the app exports the request’s spans and feedback to the trace collector.

    Key idea: Trace every LLM call with its inputs, versions, tokens and timings, linked to user feedback, so a bad answer can be explained.

  3. 3. Online metrics: feedback, cost and sampled scores

    From traces you get online metrics per route and per model version: feedback rate (thumbs, copy, retry, escalation to a human), tokens and cost per request, time to first token, refusal and “I don’t know” rates, and retrieval stats such as how often nothing relevant was found.

    For quality you can’t label by hand, a judge model scores a sample of traces, say 2%, against a rubric: is the answer supported by the retrieved documents? Sampled scores are noisy and lag behind, but they turn “users seem unhappy” into a trend you can watch.

    Scene: The trace collector sends a sample of traces to a judge model, which returns a groundedness score. Online metrics such as feedback rate, cost per request and time to first token are annotated on the collector.

    Key idea: Online signals tell you how the live system is doing; combine cheap implicit feedback with sampled, rubric-based scoring.

  4. 4. Offline evaluation: a fixed test set for answers

    Online signals arrive after users are affected. An offline evaluation set catches problems before: about 200 real, representative questions (taken from traces, cleaned of personal data) with what a good answer must contain, plus known hard cases and past failures.

    An eval runner replays them through the same pipeline and grades the answers: deterministic checks where possible (valid JSON, cites a document, contains the right policy number, no forbidden content), rubric scores from a judge model for the rest. The result is a score per version: v1 with prompt v7 scores 86% here (illustrative). Like unit tests, the set grows with every incident.

    Scene: The eval runner reads cases from the golden set, sends them through the RAG app, then asks the judge model to grade the answers. Version v1 scores 86% (illustrative).

    Key idea: A versioned eval set turns “seems better” into a number you can compare before shipping.

  5. 5. The judge is a model too

    LLM judges are useful and biased. Known effects: preferring the answer shown first (position bias), preferring longer answers (verbosity bias), preferring text in their own style, and giving different scores to the same input on different runs.

    Here the runner asks the judge to compare answers A and B twice, swapping the order. The judge picks whichever came first both times, so the comparison is discarded. Practical rules: check the judge against human labels on a sample and measure agreement; use specific rubrics and pass/fail questions instead of 1–10 scores; swap positions in pairwise tests; pin the judge model version; and report uncertainty. On 200 cases, a pass rate of 85% has a 95% interval of roughly ±5 points, so 85% vs 83% is noise.

    Scene: The eval runner asks the judge model to compare two answers, then asks again with the order swapped. The judge prefers whichever answer comes first, so the comparison is discarded.

    Key idea: Calibrate the judge against humans, control for its biases and treat small score differences as noise.

  6. 6. A new model, straight to production

    A newer model is released and someone switches the router to Model v2 for all traffic, same prompt, no evaluation. The simulation shows the part you can see: v2 writes longer answers, so P95 rises from a little over 2 s to about 3.5 s. Errors stay at zero; nothing pages anyone.

    The part you can’t see without evals: on the golden set, v2 with the old prompt scores 78% instead of 86%. It ignores an instruction to always cite the policy section and formats lists differently, which breaks a parser downstream. Users notice days later.

    Scene: The router sends all traffic to Model v2. P95 latency rises to about 3.5 s while the error rate stays at zero; the quality drop is not visible in these metrics.

    Key idea: Model and prompt changes are code changes: without an eval run, regressions ship silently.

  7. 7. Roll back, then gate changes on the eval set

    The router goes back to v1 and latency returns to normal. From now on, any change to the model, the prompt, the retrieval settings or the judge runs the eval set in CI first, and the change ships only if the score does not drop by more than the noise margin and no critical case fails.

    The runner replays the golden set against v2: 78%, blocked. The team adjusts the prompt for v2 and makes answers shorter; the next run scores 85%, within noise of v1, with v2’s other advantages. Now it can go to real users, carefully.

    Scene: All traffic is back on Model v1 and latency returns to normal. The eval runner tests Model v2 on the golden set before any rollout.

    Key idea: An eval gate in CI makes every model or prompt change prove itself on the same cases before users see it.

  8. 8. Canary by version, compared in traces

    v2 with the new prompt (about 1.5 s per answer) goes to 10% of traffic. Every trace carries the model and prompt version, so dashboards compare the two groups side by side: latency, cost per request, feedback rate and sampled judge scores.

    Overall P95 barely moves, and nothing fails. If v2’s numbers hold for a few days the share goes up; if they don’t, one config change sends everything back to v1. Offline evals catch known problems; the canary catches the ones your eval set doesn’t contain yet.

    Scene: The router sends one request in ten to Model v2. Overall P95 stays close to the v1 baseline, nothing fails, and traces are compared by model version.

    Key idea: Ship model changes like any risky deploy: small share, compared by version, easy rollback.

  9. 9. Observe the system, evaluate the answers

    Two loops work together. Observability (traces, online metrics, feedback, sampled scores) tells you how the live system behaves and explains individual bad answers. Evaluation (a versioned golden set with deterministic checks and calibrated judges) tells you whether a change is better before you ship it, and each production failure becomes a new eval case.

    Treat prompts, model versions, retrieval settings and judge rubrics as versioned artefacts, and record those versions on every trace.

    Scene: The full setup: the serving path with two model versions behind a router, the trace collector and judge for online signals, and the golden set and eval runner for offline evaluation.

    Key idea: Trace everything with versions, gate every change on evals, and turn production failures into test cases.