Lesson 6.4: Monitoring in production
Watch an AI feature after launch: what to log, tail delay, cost and quality drift, how big a weekly sample must be, safe releases and feeding failures back.
An eval tells you how a version of your system performs on the cases you chose, before it meets users. Launch changes the problem. Real users ask things you did not predict. Documents change. A provider updates a model overnight. Traffic doubles on a Monday and a retry bug quietly triples your bill. None of this shows up in an offline test, and much of it arrives silently: the system keeps running and keeps producing fluent text while quality or cost drifts the wrong way. Monitoring is how you see these changes soon after they happen and act on them. This lesson covers what to record, which signals to watch, why the slowest requests matter more than the average, how big a sample of reviewed answers you need to catch a drop in quality, how to set alerts that people will not ignore, how to release changes safely and how to turn what you see in production into better tests. By the end you will be able to list the layers of an AI system worth monitoring, design a log that lets you trace one bad answer, read latency percentiles and work out how often a user meets a slow request, size a weekly review sample and set an alarm line, name the kinds of drift and what causes each, plan a release with a small canary and a rollback, set cost guardrails and respond to an incident. You should have read Lessons 6.1 to 6.3. No programming is needed, and the arithmetic is percentages and powers.
What can change after launch
It helps to name the sources of change, since each calls for a different signal.
The inputs change. Users start asking about a new product, use a new slang, paste longer text or try to misuse the feature. This is input drift.
The data changes. Documents are added, removed or revised, and the index may lag behind. A policy changes and answers use the old one.
The model changes. A provider updates a model, retires an old version or changes rate limits. Behaviour can shift though your code did not.
Your own system changes. A prompt edit, a new chunk size or a library upgrade.
The world changes. An event raises demand, a competitor launches or a regulation takes effect.
Usage patterns change, so that costs and delays that were fine at 1,000 requests a day are not at 100,000.
Monitoring is the set of measurements that would tell you quickly if any of these has moved in a way that hurts.
Layers of monitoring
Think in layers, from the plumbing up to the user's experience.
Layer · What to watch · ExamplesSystem health · Is it up and fast? · Error rate, timeouts, rate-limit errors, latency percentiles, uptime
Usage and cost · How much is it used, and what does it cost? · Requests, tokens in and out, cost per request and per user, cache hit rate
Pipeline · Do the parts work? · Retrieval scores, share of questions with no good result, rerank time, tool-call failures, retries
Quality · Are the answers good? · Sampled grades, model-judge scores, citation checks, refusal and "I don't know" rates
User signals · What do users say and do? · Thumbs up or down, edits to drafts, repeated questions, escalations, abandonment
Safety and policy · Is it behaving? · Flagged outputs, blocked requests, injection attempts, personal data detected
Data freshness · Is the knowledge current? · Age of the newest and oldest indexed document, failed ingestion jobs
You do not need all of it on day one. Start with errors, latency, cost, a sample of graded answers and thumbs up or down, and add more as you learn where the system hurts.
What to log
Monitoring depends on logs. To trace a bad answer, you need enough information to replay what happened. For each request record:
a request identifier, a timestamp and the version of the prompt, model, index and code that handled it;
the user's input, and the rewritten query if there was one;
the retrieved chunks with their scores, and which went into the prompt;
any tool calls with their arguments and results;
the final prompt size and the answer, with token counts for each;
the delays of each step and the total;
any errors, retries, fallbacks or blocked content;
the user's feedback, if any.
Link the steps with the same request identifier into a trace, a timeline of one request across retrieval, reranking, generation and tools. When something is slow or wrong, the trace shows where.
Logs hold sensitive data, so handle them with care. Remove or mask personal information, such as names, phone numbers and account numbers, before storage where you can. Limit who can read them. Set a retention period, such as 30 to 90 days for raw text, and keep longer only the numbers you need. Follow the data protection rules that apply to your users, and tell users what you collect.
The tail matters more than the average
Delay is usually summarised by an average, but the average hides the experience of the unlucky. Use percentiles. The p50 is the median: half of requests are faster. The p95 is the delay that 95% of requests beat, so 5% are slower. The p99 is the delay that 99% beat.
In an imagined system, with 10,000 requests, the p50 is 1.8 seconds, the p90 is 4.1 seconds, the p95 is 6.2 seconds and the p99 is 14 seconds. The median looks acceptable. But 5% of requests, 500 of them, take more than 6.2 seconds, and 100 take more than 14. Language-model systems have long tails, because the length of the answer varies, because providers have occasional slow responses and because retries and tool calls add steps.
The tail matters more than it seems, because a user makes many requests. If 5% of requests are slow, the chance that a user who makes 10 requests in a month meets at least one slow request is 1 − 0.95 to the power 10 = 1 − 0.599 = 40%. Two in five users have a bad experience, though only one request in twenty is slow. With 50 requests a month the chance is 92%. If you can bring the slow share down to 1%, the chance over 10 requests falls to 1 − 0.99 to the power 10 = about 9.6%.
Predict first: your service has a slow-request share of 5%. A typical user makes 20 requests a month. What fraction of users meet at least one slow request in a month, roughly: one in five, one half or two thirds? Estimate before you read on.
The answer is 1 − 0.95 to the power 20 = 1 − 0.358 = 64%, about two thirds. The result is a good reason to measure the tail, and to set targets on p95 and p99 as well as the median.
Watching quality
Quality is the hardest layer to watch, because no log line says "this answer was wrong". Several sources help together.
Sampled grading. Take a random sample of live requests each week, grade them with your model judge and have people check some, as in Lesson 6.3. This is the backbone of quality monitoring.
Automatic checks on every response, where they are cheap: valid format, citations that exist, numbers that appear in the sources, no banned content.
User signals. Thumbs down, a copied answer, an edited draft, a repeated question in new words, a request for a person. They are noisy, since few users give feedback and those who do are not typical, but changes in them are informative.
Behaviour rates. Watch how often the system declines, answers "I don't know" or finds no good retrieval result. A sudden rise or fall means something changed.
How big should the weekly sample be?
A sample gives an estimate with a margin of error, as in Lesson 6.1. Suppose the pass rate has been about 90%. With a weekly sample of 100 graded answers, the standard error of the pass rate is the square root of 0.9 × 0.1 ÷ 100 = 0.03, or 3 points. A common rule is to raise an alarm when the weekly figure falls two standard errors below the baseline: 90 − 6 = 84%. That line will wrongly fire about one week in forty when nothing has changed.
But what drop can the sample reliably detect? As a rough guide, a true drop of about 2.8 standard errors is caught most of the time, which here is about 8 points. A fall from 90% to 85% would often go unnoticed with a sample of 100. To see a five-point drop reliably, you need a bigger sample. Because the standard error shrinks with the square root of the sample, halving it needs four times the sample. A weekly sample of 400 gives a standard error of 1.5 points and an alarm line at 87%.
Setting alerts people will act on
An alert that fires too often gets ignored. A good alert is specific, meaningful and has an owner.
Alert on symptoms users feel, such as error rate above 2% for five minutes or p95 latency above 8 seconds, and on cost, not on every internal wobble.
Compare with a baseline. A fixed threshold may suit errors, but cost and volume vary by day, so compare with the same day last week or with a moving average.
Use severity levels. A page for something that is broken now, a ticket for something that is drifting, a weekly report for slow trends.
Say what to do. Each alert links to a short runbook: how to check, how to roll back, who to call.
Review noisy alerts and tune or delete them. A team that learns to ignore alerts misses the real one.
Kinds of drift and how to see them
Drift · Cause · How to see itInput drift · Users ask new things or in new ways · Rising share of questions with no good retrieval result, new topics in a clustering of questions, longer inputs
Data drift · Documents change or the index goes stale · Age of indexed documents, failed ingestion jobs, answers citing old versions
Model drift · Provider updates a model · Quality score shift with no change on your side, change in answer length or style
System drift · Your own changes · Change tied to a release, visible if every request logs its versions
Cost drift · More tokens per request, retries, longer prompts · Cost per request and tokens per request over time
Pin model versions where your provider allows it, so that updates happen when you choose. When you must move, test the new version on your eval set first and release it gradually.
Releasing safely
A change should reach users in steps, with a way back.
Run the eval first, as a gate. A change that lowers the pass rate on key slices does not ship.
Shadow mode. Run the new version on live requests without showing its answers to users, and compare the results with the current version.
Canary release. Send a small share, say 1% to 5%, of real traffic to the new version, watch error rates, latency, cost and quality signals, and increase only if they hold.
A/B test when you want evidence of user impact, such as task completion or satisfaction, with enough traffic to see a difference.
Feature flags and a kill switch. The ability to turn off a feature, or switch back to the old version, in minutes without a new deployment.
A rollback plan written before the release.
Cost guardrails
Language-model costs can climb quickly and silently. Build limits into the system.
Cap tokens per request, for both the prompt and the answer.
Cap retries and loops. A loop that calls the model until it is satisfied can run up a large bill. Set a maximum number of steps.
Set a daily and monthly budget with alerts at, say, 70% and 90%, and a hard stop for non-critical features.
Watch the cost per request and its tail, not only the total. A few very long requests can account for much of the bill.
Cache and batch where you can, as Lesson 8.2 explains.
Rate-limit users to protect against abuse and runaway scripts.
When something goes wrong
Prepare for incidents before they happen.
1. Detect. An alert, a user report or a routine check.
2. Contain. Roll back, flip a flag, switch to a fallback or turn the feature off for the affected slice.
3. Diagnose. Use the trace for a failing request, and the four-question method from Lesson 5.4 for answer quality.
4. Fix and verify. Make the change and run the eval before releasing.
5. Learn. Write a short account of what happened, why it was not caught earlier and what will change. Add the failing cases to the test set.
The last step is what turns monitoring into improvement. A failure that is understood and added as a test case will not return unnoticed.
Three worked examples
Example 1: the long tail. A study assistant has a median delay of 2 seconds and a team that is pleased. A check of the 95th percentile shows 9 seconds. Students make about 20 requests a month, so 64% of them meet at least one request over 9 seconds. The trace shows that slow requests are the ones that retrieve 20 chunks and produce long answers. The team reduces the chunks sent from 20 to 8 with a reranker, caps the answer length and streams the response. The 95th percentile falls to 4 seconds, and complaints about slowness drop.
Example 2: a quiet model update. A bank's assistant is graded on a weekly sample of 100 answers, with a baseline pass rate of 90% and an alarm line at 84%. In week one it scores 91%, in week two 88% and in week three 82%, which crosses the line. The team checks the logs and finds that the provider updated the model between weeks one and two. They run the full eval set on the current model and find that refunds fell from 90% to 70%, since the new version is more willing to promise refunds. They pin the previous model version, edit the prompt and rerun the eval, and then move to the new version once refunds recover. The sample of 100 would not have caught the five-point dip in week two, but the third week did, which is why they decide to raise the sample to 200 for the highest-risk slice.
Example 3: a retry bug. A support assistant handles 100,000 requests a day at about ₹0.15 each, or ₹15,000 a day. A release introduces a bug in which 20% of requests are retried three times. Extra cost per day is 0.20 × 3 × ₹15,000 = ₹9,000, a rise of 60%. The team had set a cost alert at 1.3 times the seven-day average, which is ₹19,500, and it fires on the first day. They roll back within the hour. Without the alert the bug would have cost ₹2.7 lakh over a month.
A monitoring worksheet
1. The feature and its users. What must not break?
2. The layers. Which of system, usage, pipeline, quality, user, safety and data signals will you watch first?
3. The log. Fields, versions, trace identifier, privacy and retention.
4. The targets. Error rate, p50, p95 and p99 latency, cost per request.
5. The sample. How many answers graded a week, by whom, and the alarm line.
6. The alerts. Who is paged, for what, with which runbook.
7. The release plan. Eval gate, canary share, rollback.
8. The guardrails. Token caps, retry caps, budgets.
9. The incident routine. Contain, diagnose, fix, learn.
10. The feedback loop. How failures become test cases.
Common mistakes
Watching only the average delay.
No version in the logs, so changes cannot be tied to causes.
Logging everything with no privacy care, or logging too little to debug.
A weekly sample too small to see the drop that matters.
Alerts so frequent that they are ignored.
Letting a provider update a model without a test.
Releasing to everyone at once.
No cap on retries or tokens.
Fixing incidents without adding tests.
Key takeaways
After launch, inputs, data, models, your own changes and usage all drift. Monitoring is how you see it.
Watch layers: system health, usage and cost, pipeline, quality, user signals, safety and data freshness. Log each request with its versions and trace the steps.
Use percentiles, not averages. If 5% of requests are slow, 40% of users with 10 requests a month meet one, and 64% of those with 20.
Grade a weekly sample for quality. With a 90% baseline and 100 answers, the alarm line is about 84%, and only drops of about 8 points are reliably caught. Larger samples catch smaller drops.
Alert on symptoms, compare with baselines, give alerts owners and runbooks and prune the noisy ones.
Release in steps: eval gate, shadow mode, canary, flags and a rollback. Pin model versions.
Cap tokens, retries and budgets. After each incident, add the failing cases to the test set.
Check yourself
1. Why is the 95th percentile of latency more informative than the average?
It shows what the slowest one in twenty requests experiences, which the average hides, and users remember the slow ones.
2. If 2% of requests are slow, and a user makes 30 requests a month, about how likely is at least one slow request?
1 − 0.98 to the power 30 = 1 − 0.545 = about 45%.
3. A weekly sample of 400 answers has a baseline of 90%. What is the standard error, and the alarm line?
The standard error is the square root of 0.09 ÷ 400 = 0.015, or 1.5 points. The line is 90 − 3 = 87%.
4. Why should every log record carry the versions of the prompt, model and index?
So that a change in quality or cost can be tied to a specific release or update.
5. What is a canary release?
Sending a small share of real traffic to the new version first, watching the signals and widening only if they hold.
6. Why cap retries and loops?
A bug or a stuck loop can multiply calls and cost very quickly, and a cap limits the damage.
Try this
Plan monitoring for a feature. Set aside 60 minutes.
1. Choose an AI feature you use, run or are building.
2. Write the log fields you would keep for each request, including versions, and a privacy and retention rule.
3. Write targets for error rate, median and 95th percentile delay and cost per request.
4. Use the first simulator with your expected number of requests per user and your slow-request share to see how many users would meet a slow request.
5. Use the second simulator with your baseline pass rate and a realistic weekly sample to find the alarm line and the smallest drop you would catch.
6. Write three alerts, each with a threshold, an owner and a first step.
7. Write the release plan for the next change: eval gate, canary share, rollback trigger.
A good result is a log specification, a set of targets, a slow-request calculation, an alarm line with the smallest detectable drop, three alerts with owners and a written release plan.
Tags: AI Engineering Monitoring Observability LLM applications Production