Large language model applications in production require careful monitoring to detect issues before they impact users. Unlike traditional software, LLM systems are inherently probabilistic, making observability essential for maintaining reliability and trust.
Why LLM Monitoring Differs
Traditional application monitoring tracks request latency, error rates, and resource utilization. LLM applications add complexity: variable output quality, token usage costs, prompt drift, and model behavior changes. A response that is statistically fluent may still be factually wrong or unsafe. Monitoring must address both the infrastructure layer and the model behavior layer.
The unique characteristics of LLM systems include their probabilistic nature, where the same input can produce different outputs across runs. Small wording changes in prompts can shift results unpredictably. This means that monitoring cannot rely on deterministic comparisons alone. Instead, teams need statistical and behavioral approaches that account for variability while still flagging genuine regressions.
Cost monitoring is also critical. Token usage is the primary cost driver for LLM applications, and costs can scale quickly with usage volume and model choice. A production system must track token counts per request, per user, and per day to understand cost trends and detect anomalies.
Key Metrics for LLM Applications
Token Usage and Cost Tracking
Track input and output token counts per request, per user, and per day. This is the primary cost driver for LLM applications. Simple per-request logging captures the raw numbers, but aggregation by user, time window, and model variant reveals the patterns that matter.
For example, a single user submitting a batch of complex queries may consume more tokens than hundreds of users making simple requests. Token tracking should distinguish between input tokens (the prompt plus system instructions) and output tokens (the model's response), since pricing often differs between them. Teams should set daily budget alerts at the user, team, and application level so that unexpected usage spikes are caught early rather than discovered on the monthly bill.
Here is a hypothetical implementation pattern for tracking token usage:
class TokenTracker:
def __init__(self):
self.records = {}
def record(self, request_id, user_id, model, prompt_version,
input_tokens, output_tokens):
self.records[request_id] = {
"user_id": user_id,
"model": model,
"prompt_version": prompt_version,
"input_tokens": input_tokens,
"output_tokens": output_tokens,
"total_tokens": input_tokens + output_tokens,
}
def daily_summary(self, user_id, day):
daily = [
r for r in self.records.values()
if r["user_id"] == user_id
]
return {
"total_requests": len(daily),
"total_input_tokens": sum(r["input_tokens"] for r in daily),
"total_output_tokens": sum(r["output_tokens"] for r in daily),
}
This pattern captures the essential fields for correlation: who made the request, which model handled it, which prompt version was active, and how many tokens were consumed. The daily summary enables cost attribution per user.
Latency Monitoring
Measure end-to-end latency at each stage: validation, model call, and post-processing. Track p50, p95, and p99 latencies to understand typical and worst-case performance. Median latency tells you what most users experience, while p99 captures the tail of slow requests that may indicate resource contention or provider-side delays.
Latency monitoring should break down each stage of the pipeline rather than reporting only total time. Validation is usually fast, but complex schema validation or content screening can add measurable overhead. Model inference time varies by provider, model size, and current load. Post-processing, such as parsing JSON output or applying safety filters, adds another layer. Tracking each stage separately makes it easier to pinpoint where slowdowns occur.
Error Rate Analysis
Classify errors by type: validation errors, model timeouts, content filter triggers, and output validation failures. Track trends over time and correlate with deployment changes. Error categorization helps distinguish between application bugs, provider issues, and user input problems.
A spike in validation errors may indicate that user input patterns have changed and the validation layer needs updating. An increase in model timeouts could signal provider-side degradation. A rise in output validation failures may suggest that the model is producing responses that do not conform to the expected format, which could break downstream parsing.
Output Quality Signals
Track success and failure signals at the task level rather than only at the generation level. A response can be fluent and grammatically correct while still failing to resolve the user's request. Task completion rate—whether the user's actual need was met—is a stronger signal than token-level metrics.
User satisfaction ratings, such as thumbs-up or thumbs-down feedback, provide direct signal about output quality. Repeat contact rate for the same issue indicates that the initial response did not fully resolve the user's problem. The percentage of conversations requiring human handoff reveals where automation reaches its limits. These signals should be tracked per intent and per model version so that regressions are attributable to specific changes.
Prompt and Model Version Tracking
Track which prompt version and model variant handled each request. This enables regression detection when changes are deployed. Without version tracking, it is impossible to know whether a drop in quality was caused by a prompt change, a model update, or something else entirely.
Every logged invocation should include the model name and version, the prompt template and its version, and a request identifier. When multiple models are used in a routing architecture, the routing decision itself should also be logged. This creates an audit trail that supports root cause analysis when quality metrics shift.
Alerting Strategies
Threshold-Based Alerts
Set alerts when metrics exceed defined thresholds over a defined time window. Common thresholds include error rate above 2 percent over a five-minute window, token usage spike above 50 percent of baseline, and p99 latency above five seconds sustained for more than ten minutes.
Thresholds should be based on historical baselines rather than arbitrary numbers. A five percent error rate might be normal during a launch but concerning during steady-state operation. Teams should start with conservative thresholds and tune them based on observed incident patterns.
Anomaly Detection
Use statistical methods to detect unusual patterns that threshold-based alerts might miss. Embedding drift monitoring compares the distribution of user inputs over time against a baseline dataset. A gradual shift may indicate changing user behavior, while a sudden shift may indicate a new integration, a viral use case, or an adversarial campaign.
Sudden changes in output length or format can signal that the model is behaving unexpectedly. Unexpected increases in specific error types, such as JSON parsing failures, may indicate that prompt changes have altered model output structure.
Dead Letter Queue Monitoring
Route failed requests to a dead letter queue for later analysis. Include sufficient metadata to diagnose the root cause: user input, error type, timestamp, request ID, and model used. Monitor the dead letter queue for recurring failure patterns. High volumes of a specific error type indicate systemic issues requiring architectural changes rather than individual fixes.
Dead letter queue reviews should be part of regular operational cadence. Reviewing entries weekly can reveal trends that single alerts miss, such as slow degradation in model performance on a particular class of queries.
Observability Patterns
Structured Logging
Log every model invocation with its input, output, model version, prompt version, latency, token usage, and outcome. Use structured JSON format for machine-readable logs. Avoid logging full conversation transcripts by default unless they are encrypted and access-controlled, because user messages often contain personal data.
Instead, log derived signals: intent classification results, tool calls made, success or failure flags, and user satisfaction ratings when available. This reduces storage costs and privacy risk while still providing actionable information for debugging.
Distributed Tracing
Implement tracing across the request pipeline: API gateway, validation, model call, post-processing. Tools such as OpenTelemetry can correlate spans across services, making it possible to see where time is spent in a complex multi-service architecture. Tracing is especially valuable when validation, model inference, and post-processing run on different infrastructure components.
Dashboards
Create dashboards showing real-time metrics: request volume, error rates, cost per day, latency percentiles. Include filters by model, prompt version, and user tier so that teams can drill down into specific segments. Dashboards should update frequently enough to support incident response but not so frequently that they consume excessive resources.
Alert Channels
Route alerts to appropriate channels: Slack for team notifications, email for severity-level alerts, and paging for critical incidents. Critical alerts, such as complete service outage or sustained high error rates, should page on-call staff. Less severe alerts, such as gradual cost increases, can go to email or Slack channels for review during business hours.
Limitations
Monitoring reduces risk but does not eliminate it. Offline datasets are always incomplete, automated scorers have their own biases, and monitoring detects problems after users have already experienced them. Adversarial inputs can evade classifiers, and model updates can change behavior in ways no test anticipated.
Treat monitoring as a continuous practice, not a one-time checkpoint. Revisit alert thresholds quarterly, recalibrate metrics against human judgments, and retire cases that no longer reflect real usage. Monitoring is most effective when combined with offline evaluation, human review, and clear incident response procedures.
Conclusion
Reliable LLM applications are built on measurable evidence, not impressive demos. Token tracking gates releases, anomaly detection catches what thresholds miss, and human review closes the loop. Start with key metrics, integrate monitoring into your release pipeline, and expand coverage as you learn. Monitoring is never finished, but every iteration makes the system safer and more predictable.
For related guidance on model selection, see Evaluating and Selecting AI Models for Production Workloads. For LLM application architecture patterns, see Building Production-Grade LLM Applications: Patterns for Reliability and Scale.
Primary sources: