Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
GimmeJob
Sign in
Generative AI & LLM · Chapter 18 / 20

Generative AI & LLM

Production quality

An LLM feature that passed its evaluations can still fail in production. Users ask questions the dataset never contained, a provider updates a model, a new document confuses retrieval, latency grows with traffic, and costs drift. Production quality is the discipline of catching these changes early: release gates that block regressions before users see them, and monitoring that detects what the gates could not foresee.

This chapter covers both loops: evaluation in CI/CD and release gates, tracing and observability, online evaluation and drift detection, user feedback, performance and cost testing, model migrations, experiments with real users, and incident handling.

Prerequisites: Evaluation methodology and datasets, Statistics for evaluation, LLM-as-a-judge.

Two loops

Offline loop (before release)                 Online loop (after release)
dataset + scorers + judges                     traces of real traffic
        ↓                                              ↓
release gates in CI/CD           ──ship──▶     code checks on every request, judges on a sample
        ↑                                              ↓
new cases from production        ◀──learn──    drift alerts, feedback, incidents, error analysis

The offline loop protects users from known failures; the online loop discovers unknown ones and feeds them back as new cases. Neither works alone: a team without the online loop tests yesterday's product, and a team without the offline loop learns about regressions from its customers.

Evaluation in CI/CD

Run suites of different cost at different moments:

StageTriggerScopeTypical gate
Unit tests with fake modelsEvery pushAll deterministic codeAll tests pass
Smoke evaluationEvery pull request that touches prompts, models, retrieval or LLM code20 to 50 critical cases, code checks and a few validated judgesNo critical case fails
Full evaluationNightly and before every releaseThe whole dataset with repeated runs, all slicesNon-inferiority per metric and slice against the baseline
Red-team suiteWeekly and before releasesThe attack corpus and automated scannersNo new finding of high severity

A release gate checks several kinds of requirements at once, and one failing check blocks the release even when the headline metric improves:

Python
editable · browser sandbox
Result
Run the code to see the result.

Output:

PASS  hard: zero-tolerance safety cases failed     baseline      0  candidate      0  (must be 0)
PASS  quality: lower bound of paired difference    baseline      -  candidate -0.012  (at least -0.02)
PASS  latency: p95 end-to-end seconds              baseline    6.8  candidate    5.1  (at most 8.0)
PASS  cost: EUR per resolved conversation          baseline  0.041  candidate  0.019  (at most 0.05)
FAIL  language: Ukrainian slice pass rate          baseline   0.91  candidate   0.84  (at least 0.88)
decision: block, 1 check(s) failed

The cheaper model is as good on average, faster and half the price, and it still does not ship, because its Ukrainian answers fall below the agreed floor. Practical rules for gates:

  • Decide limits before the run, including the non-inferiority margin for quality (Statistics for evaluation).
  • Gate slices that matter, not only the average: languages, critical intents, customer segments.
  • Keep hard gates out of statistics: one leaked secret or one broken contract blocks the release.
  • Make gates cheap enough to run on every relevant change: cache model outputs by model, prompt and input, and run the expensive suites on a schedule.
  • Never retry a failing evaluation until it passes. A gate that sometimes fails is reporting real variance; measure it instead (Evaluating agents and tool use shows pass^k).

Tracing and observability

Every request to an LLM feature should leave a trace: a tree of spans for retrieval, each model call, each tool call and post-processing, with the data needed to explain the result.

Recorded per spanWhy
Inputs and outputs, with personal data redactedTo reproduce and read failures
Model ID, prompt version, parametersTo know exactly what produced the output
Tokens in and out, costTo find expensive requests and features
Latency, time to first token, retries, errorsTo find slow and failing dependencies
Retrieved document IDs and scoresTo tell retrieval failures from generation failures
Scores from code checks and judges, user feedbackTo connect quality to the trace that produced it

The OpenTelemetry semantic conventions for generative AI standardize the names of such attributes, and tools such as Langfuse and Phoenix store, search and score traces. Treat traces as sensitive data: redact before export, restrict access, and limit retention.

Performance testing

Users experience latency as two numbers: how long until the first token appears, and how long until the answer is complete. Both have long tails, because a slow tool, a retry or a long answer can multiply the time of an otherwise normal request:

Python
editable · browser sandbox
Result
Run the code to see the result.

Output:

time to first token  mean  0.99s  p50  0.61s  p95  4.94s  p99  8.87s
end-to-end latency   mean  5.67s  p50  5.25s  p95  9.77s  p99 13.42s
at 900 calls per minute about 85 calls are in flight on average

The average time to first token is under a second, but one user in twenty waits about five seconds, all because of the slow tool. Report percentiles, not averages, and set requirements on them (for example "p95 time to first token under 2 seconds"). Little's law (requests in flight = arrival rate × time in the system) turns latency into capacity: at 900 requests per minute and about 5.7 seconds per request, the system holds about 85 requests at once, and provider rate limits and connection pools must allow that much concurrency.

Load tests for LLM features add provider-specific behaviour to classic load testing: rate limits (HTTP 429) with retry-after headers, time-outs on long generations, streaming connections that stay open, and the cost of the test itself. Run them against a fake model server for the application's own behaviour, and against the real provider only at the scale you need to confirm limits. Check that clients wait at least as long as retry-after says and back off exponentially with random jitter: that turns most errors of a short spike into waiting. No retry policy creates capacity, though: when demand stays above what the limits sustain, the same share of requests fails whatever the client does.

Cost testing

Cost is a quality attribute with its own regressions: a prompt that grows by a paragraph, a model change, a retrieval change that adds context, an agent that takes more steps.

  • Measure cost per resolved task, not per call: a cheap model that needs three attempts can cost more than an expensive one that succeeds once (LLM application anatomy and APIs).
  • Put cost into the release gate, with a limit per resolved conversation.
  • Use prompt caching for long, stable prompt prefixes, and test that the cache is actually hit: a single variable value early in the prompt silently disables it.
  • Budget per user and per task to bound the damage of loops and abuse (Security, red teaming and guardrails).

Online evaluation and drift

In production there are no labels, but there are three kinds of signals:

  • Code checks on every request: schema validity, citations, links, language, length, refusals, tool errors.
  • Validated judges on a random sample: a few hundred conversations a day are usually enough to track a pass rate.
  • Distribution monitoring: the mix of languages, intents, input lengths and retrieved documents.

The question is when a change is a real problem rather than noise. Control charts from statistical process control answer it: a daily pass rate outside three standard errors of its normal level is unlikely to be chance:

Python
editable · browser sandbox
Result
Run the code to see the result.

Output:

baseline pass rate 89.0%, lower control limit 82.4%
day  1:  88.0%
day  2:  90.5%
day  3:  89.0%
day  4:  87.0%
day  5:  90.0%
day  6:  88.5%
day  7:  89.5%
day  8:  87.5%
day  9:  91.0%
day 10:  89.0%
day 11:  82.0%   ALERT
day 12:  80.5%   ALERT
day 13:  88.0%
day 14:  89.5%
population stability index of the language mix: 0.13

Days 11 and 12 fall below the control limit and deserve an investigation; days 13 and 14 suggest that the cause, for example a misbehaving retrieval index, was fixed. A small, lasting shift rarely crosses a three-sigma limit on any single day; a run rule catches it instead, for example eight days in a row on the same side of the center line (one of the Western Electric rules). Run rules raise more false alarms, so apply them to a few main metrics rather than to every slice.

The population stability index compares the mix of inputs with an earlier period; a common rule of thumb treats values below 0.1 as stable and above 0.25 as a major shift, so 0.13 is a moderate change: more Ukrainian traffic, which makes the Ukrainian slice of the evaluation dataset more important than before.

User feedback

  • Explicit feedback (thumbs up or down, ratings) is rare and biased toward strong reactions; use it to find cases, not to measure rates.
  • Implicit signals are more frequent: the user rephrases the question, asks for a human, abandons the conversation, or copies the answer.
  • Every piece of negative feedback is a trace to read. Feed the failures into error analysis and the dataset, so that the offline loop learns what production taught (Evaluation methodology and datasets).

Model migrations

Providers deprecate models on published schedules, and newer models change behaviour even when they score better on benchmarks. Treat a migration like any other release:

  1. Run the full evaluation with the new model on the same cases and compare as pairs; read the flipped cases.
  2. Re-tune prompts if needed, and re-validate judges if the judge model changes too.
  3. Shadow traffic: run the new model on copies of real requests without showing its answers, and compare.
  4. Canary release: route a small share of users to the new model behind a flag, watch the online signals, and widen gradually.
  5. Keep the old path available until the new one has proven itself, and plan migrations before the deprecation date, not on it.

Experiments with real users

When offline evaluation cannot answer the question (does the new answer style resolve more conversations?), run a controlled experiment: randomize users between the current and the new version, and compare outcome metrics such as resolution rate, together with guardrail metrics such as escalations and complaints. Before reading any result, check that the split matches the design: a sample ratio mismatch, such as 5,000 users in one arm and 5,300 in the other, means that the assignment or the logging is broken and the results cannot be trusted.

The most common mistake is to watch the results every day and stop as soon as the difference looks significant. Each look is another chance for noise to cross the threshold:

Python
editable · browser sandbox
Result
Run the code to see the result.

Output:

false alarms when checking every day and stopping at the first significant result: 21.0%
false alarms when analysing once, at the planned end: 3.8%

Both arms are identical, so every declared winner is wrong. Analysed once at the planned end, about 4% of these experiments produce a false alarm, close to the designed 5%; with daily peeking, about one in five does. Decide the sample size in advance (Statistics for evaluation) and analyse once, or use methods made for continuous monitoring, such as always-valid sequential tests.

Incidents and rollback

  • Feature flags for prompts, models and retrieval settings, so that a bad change can be reverted in minutes without a deployment.
  • Fallbacks: a simpler model, a static answer or a hand-over to a person when the model, the provider or a guardrail fails.
  • Runbooks for the predictable incidents: provider outage, rate limiting, cost spike, injection attack, harmful output.
  • Blameless postmortems that end with new regression cases, so that the same failure is caught by the offline loop next time.

Case study: the Learning Path Advisor of this site

The Learning Path Advisor of GimmeJob applies several practices of this chapter:

  • Traces with quality scores. Every request is traced in Langfuse with scores such as the top retrieval score, the share of grounded items, the validity of cited sources and whether the produced learning map is connected.
  • Deterministic checks before display. Cited links are validated by shape against canonical learning routes, so a model cannot send a user to an invented page.
  • Graceful degradation. When vector search is unavailable, a lexical ranker in the same pipeline keeps retrieval working (Evaluating RAG systems).
  • Tested without a model. The application code around the model has unit tests with fakes, and the AI service has its own test suite in CI (Testing LLM code without the model).

Example project

The methods of this chapter are implemented and tested in examples/llm-testing/15-production-quality: a release gate with hard, quality, latency, cost and slice checks; a tracer with nested spans, redaction and cost per trace; latency percentiles, Little's law and a load simulation against a fake provider with rate limits; a control chart, a run rule and a drift index for online monitoring; and experiment simulations that show the cost of peeking and two ways to look safely. All tests run offline, without a model or API keys:

uv sync --project examples/llm-testing
uv run --project examples/llm-testing pytest examples/llm-testing/15-production-quality

Common mistakes

  • Evaluation only before the first release, with no online loop.
  • Gates on the average only, without slices, latency and cost.
  • Retrying failing evaluations until they pass.
  • Averages instead of percentiles for latency.
  • Retries without backoff, or retries expected to make up for missing capacity.
  • Traces without model and prompt versions, or traces with personal data in plain text.
  • Explicit feedback used as a quality metric.
  • Model migrations done on the deprecation date, without paired evaluation or a canary.
  • Stopping experiments at the first significant result.
  • Incidents fixed without new regression cases.

Summary

  • Production quality is two loops: offline evaluation with release gates, and online monitoring that feeds new cases back.
  • Run suites of different cost at different moments, and gate on hard checks, quality with a margin, slices, latency and cost together.
  • Trace every request with versions, tokens, cost, latency, retrieval and scores, and redact personal data.
  • Measure latency in percentiles, plan capacity with Little's law, and test cost per resolved task and cache hits.
  • Monitor online with code checks on all traffic, validated judges on a sample, control charts and drift indices.
  • Treat model migrations as releases with paired evaluation, shadow traffic and canaries.
  • Plan experiments in advance and do not stop at the first significant look; keep fallbacks, flags and runbooks for incidents.

Source registry

20 chapter references
OpenTelemetry GenAI Semantic Conventions

Standard span names and attributes for model calls, tools, retrieval and agents, used by the tracer of the example project.

OpenTelemetry · standard
Source ↗
LLM observability and application tracing

Traces, nested observations and scores for LLM applications, as used by the Learning Path Advisor of this site.

Langfuse · official docs
Source ↗
Phoenix: AI observability and evaluation

Open-source tracing based on OpenTelemetry and evaluation of LLM applications.

Arize AI · tool
Source ↗
Monitoring Distributed Systems

The four golden signals, and why latency is watched in percentiles rather than averages.

Google — Site Reliability Engineering (O'Reilly, 2016) · article
Source ↗
A Proof for the Queuing Formula: L = λW

Little's law: requests in the system equal the arrival rate times the time in the system, used for capacity planning.

John D. C. Little — Operations Research 9(3), 1961 · paper
Source ↗
Timeouts, retries, and backoff with jitter

Engineering reference for retry budgets, exponential backoff, jitter and the danger of layered retries.

Amazon Builders' Library · article
Source ↗
API errors

HTTP error codes, including 429 rate limits and 529 overloaded, used for the retry policy.

Anthropic · official docs
Source ↗
Prompt caching

Cache reads billed at a fraction of the input price, and why a cache hit needs an identical prompt prefix.

Anthropic · official docs
Source ↗
Prompt caching

How cached input tokens are reported and discounted, used in the cost model.

OpenAI · official docs
Source ↗
Proportions Control Charts (section 6.3.3.2)

Control limits of a p-chart for a daily pass rate: the average rate plus and minus three standard errors.

NIST/SEMATECH e-Handbook of Statistical Methods · official docs
Source ↗
What are Variables Control Charts? (section 6.3.2)

The Western Electric rules, including eight consecutive points on one side of the center line.

NIST/SEMATECH e-Handbook of Statistical Methods · official docs
Source ↗
Statistical Properties of Population Stability Index

The population stability index, its statistical properties and the common thresholds of 0.1 and 0.25.

Bilal Yurdakul — doctoral dissertation, Western Michigan University, 2018 · paper
Source ↗
A Field Guide to Rapidly Improving AI Products

Looking at data, simple annotation tools and making evaluation part of everyday product work.

Hamel Husain · article
Source ↗
How is ChatGPT's behavior changing over time?

Evidence that the behaviour of the same API model changes between versions, motivating version pinning and regression testing.

Chen, Zaharia, Zou — arXiv · paper
Source ↗
Model deprecations

The model lifecycle and retirement dates, with the advice to test replacements well before retirement.

Anthropic · official docs
Source ↗
Deprecations

Shutdown dates and recommended replacements for OpenAI models.

OpenAI · official docs
Source ↗
Canarying Releases

Releasing a change to a small, time-limited share of production and comparing it with the rest before widening the rollout.

Google — The Site Reliability Workbook (O'Reilly, 2018) · article
Source ↗
How Not To Run an A/B Test

Why stopping an experiment as soon as it looks significant inflates false positives.

Evan Miller · article
Source ↗
Always Valid Inference: Bringing Sequential Analysis to A/B Testing

The mixture sequential probability ratio test: results that stay valid when an experiment is checked continuously.

Johari, Pekelis, Walsh — arXiv · paper
Source ↗
Diagnosing Sample Ratio Mismatch in Online Controlled Experiments: A Taxonomy and Rules of Thumb for Practitioners

A sample ratio mismatch as the symptom of broken assignment or logging, and how to diagnose it.

Fabijan et al. — KDD 2019 · paper
Source ↗