MLflow for LLMOps
Tracking prompts, chains, and models — registries, signatures, and evaluation hooks used in Databricks GenAI paths.
What MLflow is (for LLM teams)
MLflow is an open MLOps platform: experiment tracking, artifact storage, model registry, and (increasingly) GenAI/LLM evaluation hooks. Databricks and many lakehouse shops standardize on it; the habits transfer even if you use Weights & Biases for day-to-day compare UX.
LLMOps is MLOps with messier artifacts. You version more than .pt / .safetensors weights:
| Artifact | Why it changes behavior |
|---|---|
| Prompt template + hash | Silent product regressions |
| Retriever + embedder IDs | RAG quality cliffs |
| Chunking / metadata schema | Recall@k swings |
| Tool / MCP schemas | Agent trajectories |
| Eval suite version | Unfair “wins” |
| Model / LoRA adapter IDs | Capability + license lineage |
| Guardrail config | Safety false-positive rate |
flowchart LR
Exp[Experiment runs] --> Reg[Model / prompt registry]
Reg --> Stage[Staging]
Stage --> Gate[Eval gate]
Gate --> Prod[Production endpoint]
Prod --> Mon[Monitoring / traces]
Mon --> Exp
Interview cue: List five artifacts you’d version for a RAG bot and how you’d gate a production alias flip.
The engineering problem
Without a registry + tracking loop:
- “What beat baseline last Tuesday?” lives in Slack
- Prod prompt ≠ the prompt that passed eval
- LoRA adapters ship without pointer to base revision
- Offline and online metrics disagree with no shared IDs
- Rollback means “find the old file on someone’s laptop”
MLflow (or equivalent) makes lineage + promotion first-class — the release control plane for GenAI.
Architecture: pieces you will touch
| Component | Role |
|---|---|
| Tracking server | Params, metrics, tags, run IDs |
| Artifact store | Prompts, eval JSON, adapters, plots |
| Model Registry | Named models, stages/aliases, versions |
| Signatures | Declared I/O schema for a logged model/chain |
| Evaluation APIs | Score datasets; attach metrics to runs |
flowchart TB
Code[Git SHA] --> Run[mlflow run]
Data[Golden set version] --> Run
Run --> Arts[Artifacts: prompt / adapter / preds]
Run --> Reg[Registry version]
Reg -->|alias staging| Gate[Eval gate]
Gate -->|alias production| Serve[Serving endpoint]
Mental model: a run is one experiment; a registered version is a promote-able pointer; an alias (staging / production) is what serving should resolve — not a floating “latest file on disk.”
How it fits LLM apps
| Workflow | What to log |
|---|---|
| Prompt A/B | prompt hash, model id, judge scores |
| RAG experiments | chunk size, top-k, embed model, recall@k |
| LoRA / SFT | lr, rank, steps, task metrics (LoRA/QLoRA) |
| Agent harness | max steps, tool schema version, success rate |
| Release gate | eval suite id + pass/fail artifact |
flowchart LR
Dev[Dev iterate] --> Track[MLflow / W&B runs]
Track --> Reg[Registry]
Reg --> Deploy[Deploy alias]
Deploy --> OTel[Prod OTel traces]
OTel --> Sample[Online eval sample]
Sample --> Track
Prod traces (OpenTelemetry for LLMs) and experiment trackers are complements: traces debug a request; MLflow/W&B compare versions.
How to use (shape)
# Shape only — APIs evolve; pin mlflow version
import mlflow
mlflow.set_experiment("rag-refund-bot")
with mlflow.start_run(tags={"git": "abc123", "suite": "refund-v3"}):
mlflow.log_params({
"embed_model": "text-embedding-3-small",
"chunk_size": 512,
"top_k": 5,
"prompt_hash": "p_7f3a",
"generator": "gpt-4.1-mini",
})
# ... run harness ...
mlflow.log_metrics({"recall_at_5": 0.81, "judge_pass": 0.74})
mlflow.log_text(prompt_template, "prompt.txt")
mlflow.log_dict(preds, "preds.json")
# mlflow.log_model(...) / register_model(...) when packaging a chainSignature habit: declare expected inputs (query, tenant_id) and outputs (answer, citation_ids) so serving and eval disagree loudly instead of silently.
Promotion sketch
- Register version from the winning run
- Assign
stagingalias - Run gated eval suite (evals fundamentals; guided Evals, guardrails, safety)
- Flip
productionalias only on pass - Keep previous alias for instant rollback
sequenceDiagram
participant Dev as Engineer
participant MF as MLflow registry
participant Gate as Eval gate
participant Svc as Serving
Dev->>MF: Register v12 from run
Dev->>MF: alias staging = v12
Dev->>Gate: Run suite refund-v3
Gate-->>Dev: Pass
Dev->>MF: alias production = v12
Svc->>MF: Resolve production
MF-->>Svc: v12
What “good lineage” looks like
| Field | Example | Joins to |
|---|---|---|
git_sha |
abc123 |
Code |
prompt_hash |
p_7f3a |
Prompt artifact |
eval_suite_id |
refund-v3 |
Labels / rubrics |
model_version |
registry:/rag-bot/12 |
Weights / chain |
trace_id (prod sample) |
… |
OTel |
Serving should resolve alias → immutable version, then stamp that version on every OTel span.
Decision tree: tracker vs registry vs traces
| Question | System of record |
|---|---|
| Which experiment won offline? | MLflow / W&B runs |
| What is production allowed to serve? | Registry alias → version |
| Why did this user fail right now? | OTel traces |
| Did online quality drift this week? | Online eval samples → new runs |
Failure modes
- Logging PII in preds tables — redact or hash
- Unversioned prompts — registry points at model weights only
- Floating
latestin prod — always resolve alias → version number - Eval suite drift — bump suite version when labels/rubrics change
- Offline win, online loss — tie prod
prompt_version/model_versioninto OTel - Adapter without base pin — cannot reproduce LoRA
- Treating tracker as source of truth for code — code stays in git; tracker stores pointers
- One giant experiment — cannot filter; use tags + naming conventions
Production checklist
- Every promote goes through registry aliases — no ad-hoc file copies.
- Prompts, chunkers, embedders, and eval suites versioned as first-class artifacts.
- Signatures on logged chains.
- Redaction policy for preds / traces artifacts.
- Rollback drill: flip
productionto previous version in staging monthly. - Prod spans include
model_version+prompt_version. - Dual-track with W&B for research UX is fine — one promote path to prod.
Alternatives and companions
| Tool | Strength |
|---|---|
| Weights & Biases | Great compare UX; teams often dual-track concepts |
| LangSmith / provider dashboards | Trajectory UX / cost — not full registry |
| Git + object store only | Fine for solo labs; weak promotion story |
| Feature stores / lakehouse | Data plane; still need prompt/model lineage |
Databricks GenAI paths often wire MLflow registry → serving. You can recreate the pattern elsewhere: immutable versions + aliases + eval gates.
Micro-project
- Log a RAG chain run: params + metrics +
prompt.txtartifact. - Register two versions; assign
staging/productionaliases. - Fail a deliberate eval gate; show rollback to previous alias.
- Pair with Weights & Biases compare habits and Deploy, cost, latency, observability runbooks.
Related
Key Tech: Weights & Biases. Core: evals fundamentals. Guided Evals, guardrails, safety and Deploy, cost, latency, observability. Advanced: fine-tuning LoRA/QLoRA.