LLMOps: evaluation, observability, and versioning of prompts and models in production
How to take LLM applications to production with engineering discipline: prompts versioned in Git, automated evaluations in CI, traces with OpenTelemetry, guardrails, prompt canaries, and cost and latency SLOs.
AI$ pytest tests/evals -q▍Someone tweaks a sentence in the support assistant’s prompt, the deploy passes every test, and two days later the team finds out the answers have become longer, more expensive, and started making up order numbers. No alert fired, because nothing “broke.” LLMOps is the set of practices that prevents this scenario: treating prompts and models as code, measuring quality before and after the deploy, and seeing what happens in every request.
What changes compared to MLOps and DevOps
The foundations still apply — versioning, CI/CD, observability, gradual rollouts — but three things change:
- Non-deterministic outputs: the same input can produce different answers. A test that compares exact strings won’t work.
- Prompts are code: a text change alters the system’s behavior as much as a Python change does — and it needs review, testing, and rollback.
- Quality is hard to measure: there is no “status 200” for “the answer is correct and useful.” You have to combine assertions, automated evaluation, and human review.
On top of that, you often don’t train the model: you consume a third-party model whose behavior can change between versions.
The lifecycle
develop ───────> evaluate ──────> release ───────> observe ────────> learn
(prompt, model, (evals in CI, (canary, A/B, (traces, cost, (feedback and failures
parameters, RAG) reference feature flag) latency, SLOs) become new test
dataset) cases)
^ │
└────────────────────────────────────────────────────────────────────┘
Versioning: prompts are code
Keep prompts and parameters in Git, next to the application, not in a text field edited directly in production:
# prompts/incident-summary.yaml
id: incident-summary
version: 7
model:
provider: provider-x
name: exact-model-identifier # pinned version, never a "latest" alias
temperature: 0.2
max_tokens: 600
system: |
You summarize incidents for the platform team.
Answer in at most 5 bullet points and cite the alert IDs.
If information is missing, say what is missing. Do not make up data.
Three practical rules:
- Pin the model version. Aliases that point to “the latest version” change behavior without a single commit from you.
- Version everything that affects the output: prompt, model, temperature, RAG configuration (chunk size, top-k).
- Record the version on every request, so you know which combination produced each answer.
Prompt-writing techniques are covered in prompt engineering for tech professionals.
Evaluation before the deploy
Reference dataset
The starting point is a golden dataset: dozens to hundreds of real, representative inputs, along with what’s expected from the answer — facts that must appear, things that must not appear, expected format. Include hard cases and cases that have already caused trouble in production.
Offline evals in CI
Every change to a prompt, model, or parameter runs the evaluation suite, just like any regression test. The example is illustrative: generate() is your function that calls the model with the versioned prompt.
# tests/evals/test_incident_summary.py
import json
import pytest
from app.llm import generate # placeholder: calls the model with the versioned prompt
with open("tests/evals/golden/incident_summary.jsonl", encoding="utf-8") as f:
CASES = [json.loads(line) for line in f]
@pytest.mark.parametrize("case", CASES, ids=lambda c: c["id"])
def test_incident_summary(case):
response = generate("incident-summary", input=case["input"])
# deterministic assertions: cheap, fast, and reliable
for alert in case["expected_alerts"]:
assert alert in response.text, f"alert {alert} was not cited"
for forbidden in case.get("must_not_contain", []):
assert forbidden.lower() not in response.text.lower()
# operational limits
assert response.output_tokens <= 600
assert response.latency_s < 10
Since outputs vary, run critical cases more than once and set a minimum pass rate for the suite instead of requiring 100% on a single run.
LLM as a judge, with caveats
For subjective criteria (clarity, relevance, tone), a second model can score answers based on a rubric. It works, but with caveats: judges tend to prefer longer answers, may favor text from their own model, and are confidently wrong at times. Use objective rubrics, low temperature, and calibrate the judge by comparing its scores with human reviewers’ on a sample. Human review is still needed for the highest-risk cases.
Metrics
| Metric | Question it answers | How to measure |
|---|---|---|
| Correctness and faithfulness | Is the answer right and grounded in the sources? | Assertions, LLM as a judge, human review |
| Relevance | Does it answer what was asked? | LLM as a judge, user feedback |
| Toxicity and safety | Is there offensive content, data leakage, or a policy violation? | Classifiers, guardrails, adversarial tests |
| Latency | How long until the first token and until the end? | Traces and histograms (p50/p95) |
| Cost per request | How much does each answer or task cost? | Tokens × configured price |
Observability in production
Every request should produce a trace with: prompt version, model, retrieved documents (IDs, in the case of RAG), input and output tokens, latency, cost, and errors. OpenTelemetry has GenAI semantic conventions, still evolving, with attributes such as gen_ai.request.model and gen_ai.usage.input_tokens — check the current specification:
from opentelemetry import trace
tracer = trace.get_tracer("incident-assistant")
def call_model(prompt, messages):
with tracer.start_as_current_span(f"chat {prompt.model}") as span:
span.set_attribute("gen_ai.operation.name", "chat")
span.set_attribute("gen_ai.request.model", prompt.model)
span.set_attribute("app.prompt.id", prompt.id)
span.set_attribute("app.prompt.version", prompt.version)
response = llm_client(prompt, messages) # placeholder
span.set_attribute("gen_ai.response.model", response.model)
span.set_attribute("gen_ai.usage.input_tokens", response.input_tokens)
span.set_attribute("gen_ai.usage.output_tokens", response.output_tokens)
return response
With LLM spans in the same trace as the HTTP request, you can correlate metrics, logs, and traces and ship everything through the same OpenTelemetry collection layer. There are also specialized tools — Langfuse, Arize Phoenix, LangSmith — and LLM integrations in platforms such as Grafana and Datadog. Choose based on what fits your stack.
Guardrails and fallbacks
- On input: size limits, detection of personal data and prompt injection attempts.
- On output: format validation (JSON with a schema), blocking forbidden content, checking that citations exist.
- Fallbacks: timeouts, retries with backoff, an alternative model or provider, and an honest degraded answer (“I couldn’t answer right now”) instead of a generic error.
Releasing changes safely
Treat a new prompt or model version like a deploy: use a feature flag to send a fraction of traffic to the new version (canary) or split users into groups (A/B), and compare quality, feedback, cost, and latency. Another option is shadow mode: the new version runs in parallel without showing its answer, purely for evaluation. Rollback becomes a configuration switch.
Feedback, SLOs, and privacy
Feedback: thumbs up/down buttons tied to the trace ID turn complaints into analyzable cases. Poorly rated answers go to a review queue and later become new cases in the golden dataset. Keep in mind that few users click: feedback is a signal, not a complete metric.
Cost and latency SLOs: set targets such as “p95 time to first token below X seconds” and “average cost per conversation below Y.” Alert on the symptom — perceived latency, error rate, daily spend above budget — not on every retry. A jump in tokens per request often exposes a prompt that has grown; see FinOps for AI.
Privacy: prompts and answers carry customer data. The GenAI conventions generally treat capturing message content as optional; if you capture it, mask personal data and secrets before storing it, preferably in the telemetry pipeline, with short retention and restricted access to traces.
Checklist
- Prompts, parameters, and model version in Git, reviewed in PRs
- Golden dataset with real cases, hard cases, and past incidents
- Eval suite running in CI on every prompt or model change
- Per-request trace with prompt version, model, tokens, latency, and cost
- Canary or A/B for prompt and model changes, with rollback via configuration
- Latency and cost SLOs with symptom-based alerts
- Personal data masked before storing prompts and answers
If you don’t measure quality, every prompt change is a blind deploy.