Sub topic 9
Monitoring Quality in Production and Closing the Feedback Loop
Assume you understand Python, production logs, basic monitoring, and how an LLM application receives a request and returns an output. This chapter focuses on what happens after deployment: measuring whether answers remain useful, finding quality failures, and feeding evidence back into development.
Quality is more than uptime
Classic service monitoring asks whether a request succeeded, how long it took, and how many resources it used. Those signals still matter for an LLM application, but a successful HTTP response can contain a wrong, incomplete, or unsafe answer.
Production quality monitoring combines several signals:
- User feedback, such as thumbs-up, ratings, corrections, or support escalations.
- Programmatic checks, such as valid JSON, required fields, citation presence, or policy violations.
- Sampled evaluations, where a human or evaluator model judges a stored interaction.
- Operational data, including latency, token usage, retries, and error rates.
- Business outcomes, such as task completion, resolution rate, or search abandonment.
Do not treat one signal as the complete truth. A user may dislike a correct answer because it is inconvenient, while a user may accept an incorrect answer without noticing.
| Signal | What it reveals | Common limitation |
|---|---|---|
| User rating | Perceived usefulness | Ratings are sparse and biased |
| Programmatic check | Format or rule compliance | It may miss meaning and factual errors |
| Sampled review | Detailed quality evidence | It costs time or model credits |
| Business outcome | Whether the workflow helped | Other system changes may affect it |
Build a feedback loop
A feedback loop is a repeatable path from production behavior to an engineering change. A useful loop has these stages:
- Capture a trace for each request, including the application version, prompt version, retrieved sources, model identifier, latency, and token counts.
- Collect feedback and sample interactions for review. Remove or protect sensitive data before storing it.
- Group failures by cause, such as missing context, poor retrieval, unclear instructions, or model refusal.
- Add representative failures to an evaluation set.
- Change one artifact at a time when possible.
- Run offline evaluations and compare the candidate with the current version.
- Release gradually and watch the same quality signals again.
The application version and retrieval configuration matter because a quality change may come from code or context assembly rather than from the model itself.
from collections import Counter
events = [
{"outcome": "accepted", "failure": None},
{"outcome": "rejected", "failure": "missing_context"},
{"outcome": "accepted", "failure": None},
{"outcome": "rejected", "failure": "wrong_format"},
]
def summarize_quality(events):
total = len(events)
accepted = sum(event["outcome"] == "accepted" for event in events)
failures = Counter(
event["failure"] for event in events if event["failure"] is not None
)
return {
"acceptance_rate": accepted / total if total else 0.0,
"failure_counts": dict(failures),
}
print(summarize_quality(events))This example uses explicit labels. In a real system, store the trace identifier with each label so reviewers can inspect the full interaction and its context.
Monitor slices, not only averages
An overall acceptance rate can hide serious failures. Compare quality by language, customer type, task, model version, retrieval status, and time period. A system may work well for short questions but fail when users provide long documents.
Use minimum sample sizes before making decisions. A small slice can fluctuate by chance. Also watch for feedback bias. Users who submit ratings are not a random sample of all users.
Set alerts for meaningful changes, such as a sustained drop in acceptance rate, an increase in unsupported claims, or a rise in empty retrieval results. Alerts should lead to an investigation, not an automatic rollback without context.
Exercise
Why should a production failure be added to an offline evaluation set?
Show answer
It makes the failure reproducible enough to test future prompt, retrieval, model, and code changes against a real quality problem.