Many AI projects shine in a notebook and then quietly degrade in production. Data changes, users behave differently, a provider updates a model, costs creep up and nobody notices until customers complain. Monitoring is how you notice early. It is a core part of operating AI systems, not an optional extra.
Why AI systems need special monitoring
Ordinary software mostly fails loudly with errors. AI systems often fail silently: they keep returning plausible answers that are wrong or less useful. Monitoring must therefore cover not only technical health but also the quality of predictions or generations, and the data flowing in.
What to monitor
1. System health
- Uptime and availability
- Error rates (timeouts, API failures, rate limits)
- Request volume and traffic patterns
- Resource usage: CPU, GPU, memory, queue length
2. Latency
- End-to-end response time, with percentiles (p50, p95, p99), because averages hide slow outliers
- Time spent in each stage: retrieval, model call, post-processing
- Time to first token for streaming chat
Slow responses frustrate users and can be a sign of overload or provider issues.
3. Cost
- Tokens or compute per request and per user
- Daily and monthly spend by feature
- Cache hit rate
- Anomalies, such as sudden spikes caused by loops or abuse
Set budgets and alerts. A bug that calls a model in a loop can burn a month's budget in hours.
4. Data quality and drift
Data drift means input data changes from what the model saw in training. Concept drift means the relationship between inputs and the correct output changes. Examples: a fraud model facing new fraud tactics, a sales forecast hit by a new competitor, a chatbot meeting a new product line.
Monitor:
- Distribution of input features (mean, ranges, categories)
- Missing values and schema changes
- Language and topic mix of user messages
- Length and format of inputs
5. Model quality
How do you know the answers are good?
- Ground-truth feedback: compare predictions with real outcomes when they become known (did the customer churn, was the transaction fraud).
- User feedback: thumbs up/down, corrections, escalations to humans, repeat questions.
- Human review samples: experts rate random conversations or decisions regularly.
- Automated evaluation: run a fixed test set periodically, and use rules or a second model to grade outputs, validated against human ratings.
- Proxy metrics: refusal rates, fallback rates, empty results, citation validity.
6. Safety and compliance
- Rates of blocked or flagged content
- Attempted jailbreaks and prompt injections
- PII detected in inputs or outputs
- Fairness metrics by group where appropriate and lawful
7. Business outcomes
Link AI metrics to results: conversion, resolution time, savings, satisfaction. A technically healthy system that does not help the business needs attention too.
Detecting drift: a simple example
The population stability index (PSI) compares the distribution of a feature in production with a reference from training. Values above roughly 0.2 are often treated as a signal of significant shift (a rule of thumb, not a law).
import numpy as np
def psi(reference, current, bins=10):
edges = np.histogram_bin_edges(reference, bins=bins)
ref_pct = np.histogram(reference, bins=edges)[0] / len(reference)
cur_pct = np.histogram(current, bins=edges)[0] / len(current)
ref_pct = np.clip(ref_pct, 1e-6, None)
cur_pct = np.clip(cur_pct, 1e-6, None)
return float(np.sum((cur_pct - ref_pct) * np.log(cur_pct / ref_pct)))
rng = np.random.default_rng(0)
training_amounts = rng.normal(3000, 800, 10_000)
this_week_amounts = rng.normal(4200, 900, 2_000) # customers now spend more
score = psi(training_amounts, this_week_amounts)
print(f"PSI = {score:.2f}", "-> investigate" if score > 0.2 else "-> stable")
Other tests include the Kolmogorov-Smirnov test for numeric features and chi-squared tests for categories.
Logging for traceability
Log enough to reproduce and investigate problems, while respecting privacy:
- Request ID, timestamp, user or session (pseudonymised)
- Model name and version, prompt template version, parameters
- Input features or a hash/summary, retrieved document IDs
- Output, confidence scores and latency
- Tool calls and results
- User feedback
Mask or avoid storing sensitive data, set retention limits and control access.
A simple structured logging helper:
import json, time, uuid
def log_ai_call(model, prompt_version, user_id, input_len, output_len, latency_ms, cost_usd, feedback=None):
record = {
"id": str(uuid.uuid4()),
"ts": time.time(),
"model": model,
"prompt_version": prompt_version,
"user": f"u_{hash(user_id) % 10_000_000}", # pseudonymised
"input_chars": input_len,
"output_chars": output_len,
"latency_ms": latency_ms,
"cost_usd": round(cost_usd, 5),
"feedback": feedback,
}
print(json.dumps(record)) # send to your log system instead of printing
Alerts and dashboards
- Build a dashboard with key panels: traffic, errors, latency percentiles, cost, quality scores, drift indicators.
- Set alerts with sensible thresholds and avoid alert fatigue: page for urgent issues (outage, cost explosion, safety incident), email or tickets for slow-moving problems (drift).
- Assign owners and write simple runbooks: what to check first, how to roll back.
Handling problems
When monitoring flags an issue:
- Triage: is it infrastructure, data, model or prompt related?
- Mitigate: roll back to the previous model or prompt version, switch to a fallback, enable stricter guardrails or route to humans.
- Investigate root cause using logs and examples.
- Fix: update data, retrain, adjust prompts or code.
- Add a regression test so it is caught next time.
- Communicate with affected users and teams.
Version everything
Track versions of models, prompts, datasets, code and configurations. Roll out changes gradually (canary releases, A/B tests) and compare against the current version before switching fully. When using third-party model APIs, watch for provider-side model updates and deprecations, and pin versions when possible.
Retraining strategy
Decide whether to retrain on a schedule (monthly), on triggers (drift or performance drop) or continuously. Validate new models on recent data and a stable benchmark before deploying. For language-model apps, "retraining" often means updating prompts, retrieval content or fine-tuning data.
Frequently Asked Questions
What is the most important thing to monitor?
Quality of outcomes, along with cost and latency. Without outcome feedback, you may not notice degradation.
How often should I review?
Automated checks daily or in real time, and a human review of samples weekly or monthly depending on risk.
Do small projects need monitoring?
Yes, at a lightweight level: error logs, cost tracking, a feedback button and a periodic sample review.
Which tools help?
General observability stacks (Prometheus, Grafana, OpenTelemetry), ML monitoring tools and LLM-tracing platforms. Start with what you already have.
Conclusion
Production AI needs continuous attention: watch health, latency, cost, data drift and real-world quality, log what you need to investigate, and have a plan for rollback and retraining. Monitoring turns silent failures into fixable problems.