LLMOps: Running AI in Production

How to operate LLM applications: tracing with OpenTelemetry, offline and online evaluation, prompt and model versioning, guardrails, cost control, resilience patterns, deployment strategies and incident handling.

On this page

Simple definition#

LLMOps is the set of practices for building, deploying, monitoring and improving LLM applications in production. It extends DevOps and MLOps with things specific to LLMs: prompts as versioned artefacts, evaluation of non-deterministic output, token cost, safety guardrails and traces of multi-step chains and agents.

Why it is different from normal operations#

Traditional service LLM application
Same input → same output Same input → different outputs
Correctness tested with assertions Quality measured with evaluation datasets and judges
Errors are exceptions and status codes Many failures are silent: fluent but wrong answers
Cost is mostly infrastructure Cost is per request, per token, and can spike with one prompt change
Behaviour changes when you deploy Behaviour can change when the provider updates a model

The LLMOps lifecycle#

Continuous improvement loop
flowchart LR
    A["Design<br/>use case, metrics, risks"] --> B["Build<br/>prompts, RAG, tools"]
    B --> C["Evaluate offline<br/>golden dataset in CI"]
    C -->|"pass"| D["Deploy<br/>canary, shadow, A/B"]
    C -->|"fail"| B
    D --> E["Monitor online<br/>traces, cost, feedback, drift"]
    E --> F["Analyse failures<br/>add cases to dataset"]
    F --> B

The key habit: every production failure becomes a test case in the evaluation dataset.

Observability: what to capture#

Capture user signals too — ratings, edits, regenerations, early stops — joined to the trace; see user feedback. For drift sources and metric categories, see AI engineering architecture.

One trace of a RAG request
flowchart TB
    T["Trace: POST /ask  2.8 s  $0.011"] --> S1["span: guardrail.input  40 ms"]
    T --> S2["span: retrieval  310 ms"]
    S2 --> S2a["embed query  60 ms"]
    S2 --> S2b["vector search  top_k=20  90 ms"]
    S2 --> S2c["rerank → 5  150 ms"]
    T --> S3["span: chat claude-x  2.3 s<br/>in 5,120 tok · out 380 tok<br/>prompt v14 · temp 0.2"]
    T --> S4["span: guardrail.output  80 ms"]
    T --> S5["feedback: thumbs down<br/>reason: outdated"]

Record for every LLM call:

  • Model name and version, parameters (temperature, max tokens), prompt template version.
  • Input and output token counts, cost, TTFT and total latency, finish reason.
  • Retrieved document IDs and scores; tool calls with arguments and results.
  • User feedback and evaluation scores linked to the trace.
  • Prompts and completions only according to data policy — they often contain personal data. Mask, sample, restrict access and set retention.

OpenTelemetry GenAI semantic conventions define standard attribute names (for example gen_ai.request.model, gen_ai.usage.input_tokens, gen_ai.usage.output_tokens). Spring AI emits Micrometer observations that follow them; see Spring AI in production.

Dashboards and alerts#

Metric Why
Requests, error rate, 429s, timeouts Availability and provider health
p50/p95 TTFT and total latency User experience
Tokens and cost per request, per user, per feature Cost control, chargeback, anomaly detection
Retrieval hit rate, empty-retrieval rate RAG health
Online eval scores (faithfulness, relevance) on sampled traffic Quality drift
Guardrail trigger rate, refusal rate Safety and over-blocking
User feedback (thumbs, escalations to human) Real-world quality

Evaluation in the pipeline#

  • Offline (pre-release): run the golden dataset on every prompt, model, retrieval or code change; block release if scores drop below the baseline.
  • Online (production): sample live traffic and score it with LLM-as-judge and heuristics; track user feedback; run A/B tests for changes.
  • Regression on model updates: pin model versions where providers allow it; re-run the suite before moving to a new version.

Details of metrics and judges: RAG evaluation and agent evaluation.

Resilience patterns#

LLM providers are remote dependencies with high latency, rate limits and occasional outages.

Resilient model call
flowchart LR
    A["Call"] --> T["Timeout<br/>per call"]
    T --> R["Retry<br/>backoff + jitter on 429/5xx"]
    R --> CB{"Circuit breaker<br/>open?"}
    CB -->|"closed"| P["Primary model"]
    CB -->|"open"| F["Fallback model<br/>other provider or region"]
    P -->|"fails"| F
    F -->|"fails"| D["Degraded mode<br/>cached answer, search results only,<br/>or 'try later'"]

Also: bulkheads (separate thread pools/queues per feature), queue-based load levelling for batch work, idempotency for actions triggered by agents, and graceful degradation designed with the product owner.

Cost control#

  • Per-team budgets and quotas at the gateway; alerts on spend anomalies.
  • Prompt caching, response caching (exact and semantic), batch APIs for offline work.
  • Routing to smaller models; trimming retrieved context; limiting max output tokens.
  • Agent step budgets: maximum iterations, tool calls and tokens per task.

Deployment strategies#

Strategy Use for
Shadow New model/prompt runs on live traffic, outputs logged not shown; compare offline.
Canary Small % of users get the change; watch metrics; roll forward or back.
A/B test Measure business outcome (resolution rate, CSAT) between variants.
Feature flags Switch prompts/models per tenant or segment without redeploying.

AI incident handling#

Typical AI incidents: harmful or wrong output reaching customers, prompt injection leading to data exposure, runaway agent cost, a provider model update causing quality regression.

Runbook essentials: a kill switch per feature, the ability to roll back prompt and model versions independently of code, trace search by user/session, a process to notify risk and data-protection teams, and a post-incident review that adds test cases.

Common mistakes#

Review questions#

How do you monitor an LLM application in production? Distributed tracing of every step (retrieval, model calls, tools) with model, prompt version, tokens, cost and latency; dashboards for availability, latency, cost and guardrail triggers; online evaluation of sampled traffic for faithfulness and relevance; user feedback; and alerts on drift and cost anomalies.

How do you safely release a prompt change? Version it, run the offline evaluation suite in CI against the baseline, review, deploy via canary or A/B with feature flags, monitor online metrics, and keep instant rollback.

What resilience patterns apply to LLM calls? Timeouts, retries with exponential backoff and jitter for 429/5xx, circuit breakers, fallback to another model or provider, bulkheads, queues for batch work, and a designed degraded mode.

How do you control LLM cost? Budgets and quotas at the gateway, cost attribution per team, caching (prompt and response), model routing, context trimming, output limits, batch APIs and agent step limits.

Summary#

  • LLMOps adds prompt versioning, evaluation of non-deterministic output, token cost and safety to DevOps.
  • Trace every step with OpenTelemetry GenAI conventions; protect prompt logs as personal data.
  • Evaluate offline in CI and online on sampled traffic; turn failures into test cases.
  • Treat providers as unreliable dependencies: timeouts, retries, circuit breakers, fallbacks.

References#