Sub topic 14
Putting it together: the LLMOps loop
This chapter assumes that you understand the classic machine learning lifecycle, can write basic Python, and know how production services use logs and monitoring. The goal is to connect those ideas into one operating loop for an application that calls a pretrained large language model.
Classic MLOps manages data, training runs, model artifacts, deployment, and drift. LLMOps keeps those controls but adds application-specific artifacts and risks. The prompt, model identifier, generation settings, retrieved documents, safety rules, and tool definitions can all change the behavior of the system.
The loop from change to learning
An LLMOps loop usually follows this path:
- Define a change. This might be a new prompt, model version, retrieval setting, or safety rule.
- Record the change as a versioned artifact. Give the complete configuration an identifier.
- Run an offline evaluation set. Test representative inputs, edge cases, safety cases, and expected behavior.
- Gate the release. Reject the change if quality, cost, latency, or safety checks fail.
- Deploy gradually. Use a canary or limited traffic percentage before serving every request.
- Trace production requests. Record version IDs, latency, token counts, errors, and evaluation signals.
- Review feedback. Turn failures and useful user feedback into new evaluation cases.
- Repeat, or decide that a larger change, such as fine-tuning, is justified.
The important boundary is the release gate. A prompt that looks better in one example can still increase hallucinations, token cost, or refusal errors elsewhere. The gate should therefore combine several checks.
| Signal | Example check | Typical response to failure |
|---|---|---|
| Quality | At least 90% of golden cases pass | Revise the prompt or retrieval |
| Safety | No known injection case causes data disclosure | Block the release |
| Cost | Average tokens stay below the budget | Shorten context or output |
| Latency | P95 latency stays below the service target | Change the model or workflow |
A small release gate
The following example treats each evaluation result as a pass rate. Repeated runs matter because model output can vary even when the input and configuration stay the same.
def gate(report, minimum=0.9):
failures = [
item["id"]
for item in report
if item["pass_rate"] < minimum
]
return not failures, failures
report = [
{"id": "duplicate_charge", "pass_rate": 1.0},
{"id": "missing_invoice", "pass_rate": 0.67},
]
approved, failures = gate(report)
if not approved:
print("Blocked:", ", ".join(failures))
else:
print("Approved")In a real service, the report would also include safety and operational measurements. A release record should identify the prompt version, model ID, retrieval configuration, and code revision together. Otherwise, a production trace cannot tell you which combination produced an answer.
Production feedback is part of testing
Offline tests cannot represent every customer question. Production monitoring should sample traces for review, track user corrections, and alert on changes in latency, token usage, error rate, or safety events. Store sensitive inputs carefully: redact personal data and avoid logging secrets or full documents unless there is a justified, controlled need.
When the system fails, classify the failure before changing the model. A bad answer may come from missing retrieval context, an unclear prompt, an unsuitable model, a tool error, or an unsafe instruction in user-provided text. Fine-tuning is appropriate only when a stable behavior or domain pattern cannot be achieved more simply through prompting, retrieval, or workflow changes.
Exercise
A new model improves answer quality but doubles token cost and violates the latency target. Should the release pass?
Show answer
No. The release gate must consider quality together with cost and latency. Keep the current version or change the configuration before deploying.