Navigation

Introduction to AI

Machine Learning

Deep Learning

Generative AI

Tools & Frameworks

General

AI Observability and Monitoring

AI observability is the practice of instrumenting AI systems so that their internal behavior, inputs, outputs, and performance can be measured, logged, traced, and debugged in production. As AI applications move from prototypes to production systems, observability becomes as critical for AI as it has always been for distributed software systems.

Unlike traditional software monitoring (which tracks CPU, memory, and error rates), AI observability must address challenges unique to probabilistic systems: non-deterministic outputs, semantic quality, hallucination rates, prompt effectiveness, and model drift.

Why AI Observability Is Difficult

Traditional SoftwareAI Systems
Deterministic outputsNon-deterministic outputs
Boolean pass/failSemantic quality spectrum
Known failure modesEmergent failure modes
Stack tracesMulti-step reasoning traces
Request latencyToken generation latency
Error ratesHallucination rates

An LLM can return a syntactically correct HTTP 200 response while producing completely wrong or harmful content. Standard metrics miss this entirely.

The Four Pillars of AI Observability

1. Tracing

Distributed tracing captures the full execution path of a request through an AI system:

  • User input → prompt construction → LLM call → response parsing → tool calls → final output.
  • Each step is a span with timing, inputs, outputs, and metadata.
  • Parent-child relationships between spans reconstruct the full execution tree.

For agentic applications with multiple LLM calls, tool uses, and branches, traces are essential for understanding what happened and why.

OpenTelemetry is the open standard for distributed tracing; LLM frameworks like LangChain and LlamaIndex emit traces compatible with OpenTelemetry backends.

2. Evaluation and Quality Metrics

Production AI systems require online evaluation — assessing output quality on live traffic without ground truth labels.

Automated evaluation approaches:

MetricDescriptionUse Case
LLM-as-judgeUse a separate LLM to score responsesHelpfulness, accuracy, tone
Reference-free metricsScore outputs without ground truthCoherence, relevance
Embedding similarityCosine similarity to expected answersFactual accuracy, relevance
Regex/schema checksStructural output validationJSON format, required fields
Toxicity classifiersDetect harmful contentSafety monitoring
FaithfulnessDoes the response match source documents?RAG systems

LLM-as-judge has become widely adopted because it correlates well with human judgment on many dimensions and scales to production traffic volumes.

3. Cost and Latency Tracking

LLM API calls have direct cost implications. Observability must track:

  • Token counts: Input tokens, output tokens, cached tokens.
  • Cost per request: Calculated from token counts and model pricing.
  • Total daily/monthly cost: Aggregated cost trends for budget management.
  • Latency breakdown: Time to first token (TTFT) vs. total generation time.
  • Model usage distribution: Which models are called and how frequently.

Cost spikes often indicate prompt issues (unexpected input length growth) or bugs in context management.

4. Drift Detection

AI systems degrade over time as the world changes and user behavior evolves:

  • Prompt drift: User queries shift in distribution away from the training distribution.
  • Model drift: A model update changes response behavior unexpectedly.
  • Feedback drift: User satisfaction metrics change without an obvious cause.

Detecting drift requires monitoring input/output distributions and triggering re-evaluation when significant shifts are detected.

Key Metrics to Monitor

LLM Metrics

MetricDefinitionTarget
Hallucination rateFraction of responses containing ungrounded claimsMinimize
Answer relevanceSemantic relevance to the questionMaximize
Context faithfulnessResponse grounded in retrieved context (RAG)> 0.9
Refusal rateFraction of requests that are refusedMonitor
Task success rateFraction of agent tasks completed correctlyMaximize
TTFT (P50/P99)Time to first token latency distribution< 2s P99

System Metrics

MetricDefinition
Requests per secondThroughput
Token throughputOutput tokens/second
Error rate4xx/5xx from LLM provider
Retry rateRate of 429 (throttled) requests
Cost per requestAverage API cost

Prompt Lineage and Versioning

Understanding which prompt version produced which output is critical for debugging and iteration:

  • Prompt versioning: Track changes to prompts over time with version IDs.
  • A/B testing: Route a fraction of traffic to a new prompt version and compare quality metrics.
  • Prompt-to-output linking: Associate every production output with the exact prompt template, version, and model that generated it.
  • Regression detection: Alert when a prompt change degrades quality metrics.

RAG-Specific Observability

Retrieval-Augmented Generation systems introduce additional observability concerns:

  • Retrieval quality: Are the retrieved documents relevant to the query?
  • Context utilization: Is the LLM using the retrieved context effectively?
  • Faithfulness: Does the answer follow from the retrieved context?
  • Missing context rate: How often does retrieval fail to find relevant documents?

The RAGAS framework provides automated metrics for RAG evaluation: faithfulness, answer relevance, context precision, and context recall.

Observability Tooling

ToolTypeKey Feature
LangSmithTracing & evaluationLangChain-native, online evaluation
LangfuseOpen-source tracingSelf-hostable, LLM-agnostic
Arize PhoenixOpen-source observabilitySpan-based tracing, evaluation
Weights & Biases (W&B)Experiment trackingTraining + inference monitoring
HeliconeLLM proxy observabilityCost and latency tracking
BraintrustEvaluation platformDataset-driven evaluation
MLflowMLOps platformModel tracking, evaluation

Alerting Strategy

Effective AI observability requires actionable alerts:

  • Quality alerts: LLM-as-judge score drops below threshold.
  • Cost alerts: Daily spend exceeds budget.
  • Latency alerts: P99 TTFT exceeds SLA.
  • Error alerts: Provider error rate spikes.
  • Safety alerts: Toxicity classifier triggers.

Alerts should route to the appropriate team: cost alerts to engineering, quality alerts to ML/product, safety alerts to trust and safety.

Human Feedback Integration

Online human feedback is the highest-quality signal for production monitoring:

  • Thumbs up/down ratings embedded in the UI.
  • Corrections and edits from users.
  • Escalation to human review for flagged outputs.

These signals feed back into:

  • Dataset construction for offline evaluation and fine-tuning.
  • Failure analysis to identify systematic issues.
  • Model improvement via RLHF or DPO using production feedback.

Further Reading