MLflow started as experiment tracking for data scientists and has grown into a general AI engineering platform: tracking and a model registry for classical models, and tracing, evaluation and a prompt registry for LLM applications and agents. It is a Python package plus a server, both from mlflow/mlflow, and it runs on a laptop with one command. This lesson covers the MLflow 3 data model, how to run the server properly for a team, promoting models with aliases, and the GenAI features you will reach for when an LLM app misbehaves.
- Log parameters, metrics and models to an MLflow tracking server
- Run a team MLflow server with a database backend and object-storage artifacts
- Register model versions and promote them with aliases instead of stages
- Trace an LLM application and evaluate it with built-in and custom scorers
- Version prompts in the prompt registry and load them by URI
The data model: experiments, runs, models
An experiment groups related work, such as "churn model". A run is one execution inside it, recording parameters (inputs you chose), metrics (numbers you measured, optionally per step), tags, and artifacts (files such as plots or a dataset sample). MLflow 3 adds the LoggedModel as a first-class object: a model can be logged with a name and no active run, and later runs, evaluations and traces link back to it.
import mlflow
from sklearn.datasets import load_diabetes
from sklearn.linear_model import Ridge
from sklearn.metrics import mean_squared_error
mlflow.set_tracking_uri("http://localhost:5000")
mlflow.set_experiment("diabetes")
X, y = load_diabetes(return_X_y=True)
with mlflow.start_run():
alpha = 0.5
model = Ridge(alpha=alpha).fit(X, y)
mlflow.log_param("alpha", alpha)
mlflow.log_metric("mse", mean_squared_error(y, model.predict(X)))
mlflow.sklearn.log_model(model, name="model", registered_model_name="diabetes-ridge")Autologging (mlflow.sklearn.autolog(), mlflow.pytorch.autolog() and friends) records parameters, metrics and the model for supported libraries without explicit calls. Models are saved with a flavor (sklearn, pytorch, transformers) plus the generic pyfunc flavor, so anything you log can be loaded with mlflow.pyfunc.load_model(uri) and called with .predict(), whatever library trained it.
Upgrading from MLflow 2? log_model takes name= instead of artifact_path=, and a run is no longer required to log a model. Old code still runs with deprecation warnings, but fix it before they become errors.
Running the server for a team
mlflow server (or uvx mlflow server without installing anything) starts the tracking server and UI on port 5000. It has two storage halves. The backend store holds metadata: experiments, runs, params, metrics, registry entries. SQLite (mlflow.db in the current directory) is now the default; the older ./mlruns file store is in maintenance mode. The artifact store holds the large files: models, plots, datasets.
mlflow server \
--backend-store-uri postgresql://mlflow:CHANGE_ME@db.internal:5432/mlflow \
--artifacts-destination s3://acme-mlflow-artifacts \
--host 0.0.0.0 \
--port 5000- With
--artifacts-destination, the server proxies artifact uploads and downloads, so clients need only the server URL, not cloud credentials. - SQLite is fine for one person; for a team use Postgres or MySQL, which handle concurrent writers and survive a pod restart.
- The open-source server ships basic authentication and workspaces, but put it behind your SSO proxy and TLS before exposing it beyond a VPN.
- On Kubernetes, run the server as a stateless Deployment (there is a Helm chart in the repo's
charts/folder); all state lives in the database and the bucket.
The model registry: versions and aliases
A registered model is a name, such as diabetes-ridge, holding numbered versions. Each version points at a logged model and remembers which run produced it, so you can always answer "what data and parameters made the thing in production?"
Promote with aliases: mutable, named pointers to one version, such as champion or challenger. Your serving code loads models:/diabetes-ridge@champion; promoting a new version is a single API call that moves the alias, and rolling back moves it back. The older fixed stages (Staging, Production) are deprecated in favour of aliases and tags.
import mlflow
from mlflow import MlflowClient
client = MlflowClient()
client.set_registered_model_alias("diabetes-ridge", "champion", 7)
client.set_model_version_tag("diabetes-ridge", "7", "validated_by", "ci")
model = mlflow.pyfunc.load_model("models:/diabetes-ridge@champion")To serve, mlflow models serve -m models:/diabetes-ridge@champion -p 8080 starts a local REST endpoint, and mlflow models build-docker packages a model into an image you can run anywhere, including KServe.
GenAI: tracing, evaluation and prompts
For LLM applications the questions change: not "what was the loss?" but "what did the agent retrieve, which tool did it call, why was the answer wrong, and did my prompt change make things better?" MLflow answers with traces: a tree of spans per request, recording inputs, outputs, latency and token usage. One line, such as mlflow.openai.autolog(), instruments a supported client library; the @mlflow.trace decorator instruments your own functions. Traces are OpenTelemetry-compatible.
import mlflow
from mlflow.genai import scorer
from mlflow.genai.scorers import Correctness, Guidelines
@mlflow.trace
def answer(question: str) -> str:
return call_llm(f"Answer briefly: {question}") # your model call
@scorer
def is_short(outputs: str) -> bool:
return len(outputs.split()) <= 30
data = [
{"inputs": {"question": "What does SLO stand for?"},
"expectations": {"expected_response": "Service level objective"}},
]
mlflow.genai.evaluate(
data=data,
predict_fn=answer,
scorers=[Correctness(), Guidelines(name="plain", guidelines="No jargon."), is_short],
)Correctness and Guidelines are LLM-judge scorers: they ask a judge model, which you configure, to grade each output. Custom @scorer functions are plain code and cost nothing to run. Every evaluation run is stored with its traces, so you can open a failing example and see exactly which step went wrong.
The prompt registry gives prompts the same treatment as models: mlflow.genai.register_prompt(name=..., template=...) creates a new version on each call, mlflow.genai.load_prompt("prompts:/summarize/3") loads one, and aliases work here too, so a prompt change can be reviewed, evaluated and rolled back without a code deploy.