Slides · Production: cost, serving and observability
Observability and eval pipelines
1 / 24
Observability and eval pipelines
What to record on every LLM request, what to watch live, and how to stop a regression before users meet it.
Concept
An hour of wrong answers, and nobody noticed
- At 2 am the delivery cut-off answers were wrong for an hour. Customers noticed first, in their reviews.
- Ordinary software can be unit-tested with
==. An LLM system cannot: output varies, “correct” is often a judgement, and prompt, model, retrieval and tools each change on their own schedule. - So production needs two things that work together: tracing and monitoring (online) and an evaluation pipeline (offline).
By the end you can:
- List what to record per request and why.
- Say what online monitoring catches and what only an offline golden set catches.
- Run the loop from traces to labelled cases to a gate, reading results per slice.
- Choose alerts and a privacy policy for logged prompts.
Diagram
Flight recorder and test rig
- The flight recorder (traces) tells you something went wrong after users met it. The test rig (golden set) tells you before.
- Anthropic’s engineering post on agent evals describes layers: automated evals before launch and in CI/CD, then production monitoring for drift and failures nobody anticipated. No single layer catches everything.
Diagram
A trace is timed steps under one id
- The OpenTelemetry GenAI conventions define spans for operations such as inference, embeddings and retrieval.
- Each step is a span, so you can see which stage is slow or wrong.
Compare
What to record, and the question each field answers
| Field | Question it answers | OpenTelemetry (GenAI conventions) |
|---|---|---|
| Trace id, timestamp, tenant or hashed user id | Which requests belong together? Which user to delete? | Trace id is built into OpenTelemetry span context; no GenAI attribute for tenant |
| Versions: prompt, embedding model, chunker, index, reranker | What changed when quality moved? | No GenAI attribute; use your own. gen_ai.request.model and gen_ai.response.model cover the model |
| Rewritten query, retrieved chunk ids and scores | Retrieval failure or generation failure? | gen_ai.retrieval.documents (Opt-In) and gen_ai.retrieval.query.text (Opt-In) |
| Final prompt tokens; prompt text (by policy) | Can I reproduce the input and explain cost? | gen_ai.usage.input_tokens; gen_ai.input.messages (Opt-In) |
| Raw response, stop reason, tool calls | Why did it say that? Was it truncated? | gen_ai.output.messages (Opt-In), gen_ai.response.finish_reasons |
| Input, output, cached tokens; latency per stage; cost | Where do money and seconds go? | gen_ai.usage.input_tokens, gen_ai.usage.output_tokens, gen_ai.usage.cache_read.input_tokens; cost is yours |
| Errors | Reliability analysis | error.type (Stable) |
| Guardrail outcome, retries, fallbacks | Safety and reliability | No GenAI attribute; use your own |
| Outcome signals: thumbs, regeneration, copy, escalation | Weak live evidence of quality | No GenAI attribute; use your own |
- Attribute names above come from the OpenTelemetry GenAI repository’s spans and inference documents (checked 2026-10-23). Apart from
error.type, they carry Development status, so names can still change.
Worked example
Worked example: which stage is slow?
Users report that some answers take close to 10 seconds. Normal requests take about 2.9 s. Three slow traces (illustrative):
| Trace | Stage times (s) | Tokens | Verdict | First thing to check |
|---|---|---|---|---|
| A | rewrite 0.3, retrieve 4.8, rerank 0.4, generate 1.9; total 7.4 | normal | Retrieval is slow | Vector store load, index version |
| B | rewrite 0.3, retrieve 0.2, rerank 0.4, generate 9.0 (TTFT 0.6); total 9.9 | 840 output at 100 tokens/s | Answer too long | Prompt version, output limit |
| C | rewrite 0.3, retrieve 0.2, rerank 0.4, generate 6.5 (TTFT 5.8); total 7.4 | 14,000 input, 0 cached | Prompt grew and missed the cache | Chunks per prompt, prefix layout |
- The totals look alike; the per-stage spans plus token and cached-token fields separate three different causes.
- Check B: decode time 9.0−0.6=8.4 s, and 8.4×100=840 tokens.
Concept
Standard names exist, but check their status
- The GenAI conventions moved: the old opentelemetry.io spec page now says they live in a separate repository (page viewed 2026-10-23).
- The repository’s spans document is marked Development status, and its attribute tables mark individual attributes as Development too.
- Content-carrying attributes (retrieved documents, query text, output messages, system instructions, tool definitions) are marked Opt-In, and some carry a note that they may contain sensitive information, including personal data.
- Takeaway: adopt the names where they fit, keep your own field list as the contract, and treat content capture as a policy decision.
Compare
Online signals: fast, real, noisy
| Group | Example signals | What it cannot tell you |
|---|---|---|
| Reliability | Error rate, timeouts, retry and fallback rate | Whether answers are right |
| Latency | p50, p95, p99 per stage; TTFT | Why a stage is slow |
| Cost | Cost per request and per tenant; input token count | Whether the spend bought quality |
| Behaviour | Abstention rate, empty-retrieval rate, guardrail and refusal rate | Which change caused a jump |
| Quality proxies | Thumbs-down and regeneration rate; a sampled groundedness or judge score | Anything for the many users who never click |
| Drift | Shifts in query topics, retrieval score distribution, document freshness | What to fix |
- Alert on change relative to your own baseline, not on numbers copied from a blog.
- A sudden jump in abstention or refusal rate in either direction means something changed.
- Few users give feedback and those who do are not representative.
Worked example
Worked example: a baseline-relative threshold
Signal: the empty-retrieval rate. Baseline 3 percent over 2,000 requests per hour (illustrative).
standard error=np(1−p)=20000.03×0.97=0.0038alert threshold=p+3×standard error=0.03+0.0114=0.0414| Hour | Requests | Empty retrievals | Rate | Alert? |
|---|---|---|---|---|
| 1 | 2,000 | 64 | 3.2% | No |
| 2 | 2,000 | 96 | 4.8% | Yes, above 4.14% |
- “3 standard errors” is a starting choice, not a law. Tune it on your history, and allow for daily and weekly patterns in the baseline.
- The alert says behaviour changed. The trace fields (versions, retrieved ids) tell you why.
Compare
What each one catches
| Aspect | Online monitoring | Offline golden-set eval |
|---|---|---|
| When | After users are affected | Before the change ships |
| Data | Real traffic, unlabelled | Curated cases with expectations |
| Strength | Catches drift, outages, cost leaks, data changes with no release | Catches regressions in rare intents and slices; compares versions fairly |
| Weakness | Noisy; slow to move for a small slice; shows that something changed, not what | Only covers cases you thought to include; needs upkeep |
| Failure mode on its own | Aggregate rates can stay flat while a slice breaks | A passing set says nothing about tomorrow’s data |
Anthropic’s agent-evals post recommends combining three layers: automated evals “for fast iteration”, production monitoring “for ground truth”, and periodic human review for calibration (quotation marks mark its wording).
Check yourself
Check: which layer catches it?
For each incident, say whether live monitoring or the pre-release golden-set gate is the better first catch.
- One tenant’s cost per request triples because a client library retries in a loop.
- The team upgrades the judge model used for sampled quality scores, and the scores jump with no change to the answers.
- The provider starts timing out at 6 pm.
- A nightly re-embedding job fails halfway, leaving the index part old and part new.
Answer
- Live: cost per tenant and retry rate show it within minutes. 2. Offline: re-run the judge on a human-labelled set and compare agreement before trusting the new scores. 3. Live: error and latency alerts. 4. Live: no release is involved, so retrieval-score distribution, empty-retrieval rate and sampled groundedness are the early warning. A scheduled eval run after the job also helps.
Concept
What goes in a golden set
- Inputs with expectations about the output, grouped into kinds of case: should retrieve and answer, should say “I don’t know”, should ask a clarifying question, adversarial or injection attempts, and every past incident.
- Tag each case with a slice: topic, tenant type, language, difficulty.
- Start small. Anthropic’s post calls 20 to 50 tasks built from real failures “a great start” (quoted). Husain describes tests scoped by feature and scenario that are cheap enough to run on every change.
- Run it on every change to the prompt, model, retriever, chunker or embedding model, and compare with the current baseline.
- Score retrieval (did the right chunk id appear in the top k?) separately from generation (was the answer faithful and complete?). That is why the trace stores retrieved ids.
Sources[3] Your AI Product Needs Evals[1] Demystifying evals for AI agents
Diagram
The gate, step by step
Math
How noisy is a pass rate?
standard error=np(1−p)| Symbol | Meaning |
|---|---|
| p | Observed pass rate (share of cases passed) |
| n | Number of cases in the set or slice |
For the gap between two independent runs: n1p1(1−p1)+n2p2(1−p2).
| Cases n | Pass rate p | Standard error | In points |
|---|---|---|---|
| 25 | 0.9 | 250.9×0.1=0.06 | 6 |
| 100 | 0.9 | 1000.9×0.1=0.03 | 3 |
| 400 | 0.9 | 4000.9×0.1=0.015 | 1.5 |
- A rough guide that treats the cases as a random sample of future traffic. The difference between two runs is noisier than either run.
- A one-point gain on 100 cases is inside the noise. A small slice is noisy but can still show a large fall.
Worked example
Worked example: the average hides a collapse
Illustrative golden set of 150 cases, gated on quality and on p95 latency (limit 5 s, illustrative). Prompt v8 is the baseline; v9 adds more retrieved context.
| Slice | Cases | v8 passes | v9 passes | v8 p95 | v9 p95 |
|---|---|---|---|---|---|
| General | 100 | 85 (85%) | 96 (96%) | 2.1 s | 2.2 s |
| Long-document questions | 25 | 20 (80%) | 21 (84%) | 3.4 s | 9.8 s |
| Tool-call questions | 25 | 20 (80%) | 20 (80%) | 2.8 s | 2.9 s |
| Total | 150 | 125 (83.3%) | 137 (91.3%) |
- Headline quality: up 8.0 points. The standard error of the difference between two runs is 1500.833×0.167+1500.913×0.087=0.038, so the gain is about 2.1 standard errors: probably real. This treats the runs as independent; the same cases are scored twice, so it is a conservative guide.
- Long-document slice: p95 latency rises from 3.4 s to 9.8 s, over the 5 s limit, and its quality gain is only one case.
- Gate on more than one metric per slice. A better average quality score can hide a latency (or cost) regression in one slice.
Process
Closing the loop
- Sample production traces, weighted toward thumbs-down, abstentions, low-confidence retrievals, escalations and new topics.
- Label them, by people or by a calibrated judge checked by people. Fix the prompt, retrieval or data.
- Add the labelled cases to the golden set with slice tags, after redaction.
- Gate the next change on the enlarged set for quality, latency and cost, then roll out in stages.
Why calibrate a model judge: the MT-Bench paper reports that strong judges agree with human preferences more than 80 percent of the time in its setting, and also documents position, verbosity and self-enhancement biases. Husain’s advice is to align the judge with a human and track their agreement.
Sources[3] Your AI Product Needs Evals[4] Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena
Diagram
The loop as a picture
- Husain describes a cycle in which evaluating, debugging and changing the system speed one another up, and failures seen in real use become new tests.
Check yourself
Check: is the judge any good?
A team calibrates a model judge on 100 human-labelled traces. Humans marked 90 as good and 10 as bad. The judge said “good” for all 100. It reports 90 percent agreement with humans. What is wrong, and what should they measure instead?
Answer
The classes are imbalanced, so a judge that never flags anything still agrees on 90 of 100. Its recall on the bad answers is 0 of 10. Husain advises looking at precision and recall separately rather than raw agreement. The team should measure how many of the 10 bad answers the judge catches and how often it flags good ones, and improve the judge prompt until it does.
Concept
Traces are sensitive data
A trace holds user text, retrieved company documents and model output. Treat the trace store as production data.
- Redact personal data and secrets before storing, or keep identifiers and hashes instead of text.
- Restrict: most engineers get redacted views. OWASP lists least-privilege access among its mitigations for sensitive information disclosure.
- Expire: set a retention period and delete on schedule. OWASP also advises that you “maintain clear policies about data retention, usage, and deletion”.
- Honour deletion across traces, caches and exported datasets. Check your own legal requirements.
- Sample full-content capture if you do not need every request. OpenTelemetry marks content attributes as opt-in.
- Same rules for the golden set: do not copy raw production traces into it.
Sources[5] LLM02:2025 Sensitive Information Disclosure[2] OpenTelemetry GenAI Semantic Conventions
Code
Redaction and a pseudonymous id
Python
import re, hmac, hashlib
EMAIL = re.compile(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}")
PHONE = re.compile(r"(?<!\d)(?:\+?\d{1,3}[ -]?)?\d{10}(?!\d)")
KEY = re.compile(r"\b(?:sk|pk)-[A-Za-z0-9_-]{16,}")
def redact(text: str) -> str:
text = EMAIL.sub("[EMAIL]", text)
text = KEY.sub("[SECRET]", text)
return PHONE.sub("[PHONE]", text)
def pseudonym(user_id: str, secret: bytes) -> str:
return hmac.new(secret, user_id.encode(), hashlib.sha256).hexdigest()[:16]Results of running it (Python 3):
| Test | Input | Result |
|---|---|---|
ananya.rao@example.com | [EMAIL] | |
| Phone | 9876543210, and +91 9876543210 | [PHONE] |
| Key-like strings | sk-abcdef0123456789ABCD, sk-abcdef0123456789ABCD_extra, sk-ant-api03-..., sk-proj-... | [SECRET] for each, whole string |
| Other key format | ghp_AbCdEf0123456789... (40 characters) | Not caught as a key, and any 10-digit run inside is rewritten to [PHONE] |
| False positive | order 1234567890 shipped | order [PHONE] shipped |
| Name | Ananya Rao | Not caught |
| Spaced digits | 98765 43210 | Not caught |
| Same user, same key | u-42 twice | Same pseudonym |
| Different user, or different key | u-43, or another key | Different pseudonym |
- Pattern matching catches formats, not meaning. Names and unknown key formats slip through, ten-digit order ids look like phone numbers, and a partial match can leave the rest of a secret in the trace. Treat redaction as one layer, with access limits and retention.
- Store the keyed pseudonym instead of the user id. To honour a deletion request, recompute it from the user id and delete matching traces. Keep the key out of the trace store.
Check yourself
Check: a deletion request
A user asks for their data to be deleted. Engineering deletes their account rows and confirms completion. Six weeks later a support engineer finds the user’s prompts in three other places. Where would you look, and what design would have prevented this?
Answer
Look in the trace store, any response or semantic caches, exported evaluation datasets and golden-set copies, plus backups per your retention rules. The prevention is a policy applied everywhere: store a keyed pseudonymous id so records can be found and deleted, redact on write, set retention periods, and keep raw traces out of shared datasets. OWASP advises you to “maintain clear policies about data retention, usage, and deletion”. Legal specifics depend on your jurisdiction.
Concept
Common mistakes
- Logging only final answers. You cannot separate retrieval from generation.
- No version fields. “What changed?” becomes a guess.
- Trusting one average score. Read per slice, with noise in mind.
- Treating feedback clicks as the quality signal. They are sparse and unrepresentative.
- Alerting on numbers from a blog instead of your own baseline.
- No privacy policy for traces, or copying raw traces into shared datasets.
- Never feeding failures back into the golden set.
Summary
Recap
- LLM systems need tracing (flight recorder) and an offline eval gate (test rig).
- Record versions, retrieved ids and scores, tokens, latency, cost and outcome signals per request.
- Online monitoring is live but noisy; offline evaluation catches regressions before users do. Neither replaces the other.
- Read results per slice and remember small sets are noisy.
- Alert on change from your own baseline, and treat traces as sensitive: redact, restrict, expire.
- Feed bad production cases back into the golden set.
References
References & Sources
Demystifying evals for AI agents (opens in a new tab)
Mikaela Grace, Jeremy Hadfield, Rodrigo Olivares, Jiri De Jonghe2026Article
https://www.anthropic.com/engineering/demystifying-evals-for-ai-agents
Used for Evals before launch and monitoring after launch as layers; starting with 20 to 50 tasks drawn from real failures; model graders need calibration.
OpenTelemetry GenAI Semantic Conventions (opens in a new tab)
OpenTelemetry2026Specification
https://github.com/open-telemetry/semantic-conventions-genai
Used for GenAI semantic conventions (spans, metrics, events) now live in this repository; Development status; attribute names such as gen_ai.request.model and gen_ai.usage.input_tokens; content attributes are opt-in and flagged as possibly sensitive.
Your AI Product Needs Evals (opens in a new tab)
Hamel Husain2024Article
https://hamel.dev/blog/posts/evals/
Used for Looking at traces, cheap feature-scoped tests run on every change, aligning an LLM judge with humans (and not trusting raw agreement on imbalanced classes), and failures feeding new tests.
Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena (opens in a new tab)
Lianmin Zheng, Wei-Lin Chiang, Ying Sheng, Siyuan Zhuang, et al.2023NeurIPS 2023 Datasets and Benchmarks TrackPaper
arXiv 2306.05685 (opens in a new tab)https://proceedings.neurips.cc/paper_files/paper/2023/hash/91f18a1287b398d378ef22505bf41832-Abstract-Datasets_and_Benchmarks.html
Used for Strong LLM judges agree with human preferences over 80 percent of the time in the paper's setting, with position, verbosity and self-enhancement biases.
LLM02:2025 Sensitive Information Disclosure (opens in a new tab)
OWASP GenAI Security Project2025Documentation
https://genai.owasp.org/llmrisk/llm022025-sensitive-information-disclosure/
Used for Least-privilege access and clear retention, usage and deletion policies among mitigations for sensitive information disclosure.
Keys: ← → move, Home End first and last, F full screen.