Sub topic 6
Documenting versions with descriptions and tags
This chapter assumes you have a tracking server running with a SQL backend, and a registered model named iris-classifier with at least one version. Both come from the earlier chapters. You should be comfortable with MlflowClient and with reading a model version object.
A version number tells you when a model was registered. It does not tell you what the model is for, how it was validated, or whether anyone approved it. Descriptions and tags carry that information. They are the registry's metadata, and the promotion workflow in the next chapters relies on them.
Two kinds of metadata, at two levels
The registry holds metadata at two levels. A registered model is the named container. A model version is one numbered entry inside it. Each level supports a description and tags.
| Kind | Type | Typical content | Level |
|---|---|---|---|
| Description | Free text, Markdown rendered in the UI | Purpose, input expectations, training data summary | Registered model and model version |
| Tag | String key and string value | `team=fraud`, `validation_status=passed` | Registered model and model version |
Use the registered model level for facts that stay true across versions. These include the owning team, the business purpose, and the on-call contact. Use the model version level for facts about one build. These include the validation result, the data snapshot it was trained on, and the reviewer.
A new model version does not inherit tags from the previous version or from the registered model. Each version starts with whatever you give it at creation time. Your automation has to set the tags it needs on every version.
Descriptions
A description is a single block of text. Writing a description replaces the old text instead of appending to it. If you want to keep earlier text, read the current description first and write back the combined value.
from mlflow import MlflowClient
client = MlflowClient(tracking_uri="http://127.0.0.1:5000")
client.update_registered_model(
name="iris-classifier",
description=(
"Classifies iris flowers into three species from four measurements "
"in centimetres: sepal length, sepal width, petal length, petal width."
),
)
client.update_model_version(
name="iris-classifier",
version="1",
description="Logistic regression, max_iter=200, trained on the full iris dataset.",
)
rm = client.get_registered_model("iris-classifier")
mv = client.get_model_version("iris-classifier", "1")
print(rm.description)
print(mv.description)The version argument is a string in the client API, even though versions are numbers. Passing 1 usually works, but "1" is the documented form.
Write descriptions for a person who has never seen the training run. Good version descriptions answer three questions: what changed from the previous version, what data it saw, and what it should not be used for.
Tags
A tag is a key and a value, and both are strings. Setting a tag that already exists overwrites its value. Setting a tag with a new key adds it. MLflow converts non-string values to strings, so a Python 0.97 becomes "0.97". Convert values yourself so you control the format.
from mlflow import MlflowClient
client = MlflowClient(tracking_uri="http://127.0.0.1:5000")
# Facts about the model as a whole
client.set_registered_model_tag("iris-classifier", "team", "ml-platform")
client.set_registered_model_tag("iris-classifier", "task", "classification")
# Facts about one version
client.set_model_version_tag("iris-classifier", "1", "validation_status", "pending")
client.set_model_version_tag("iris-classifier", "1", "data_snapshot", "2026-11-01")
# Overwrite the value when validation finishes
client.set_model_version_tag("iris-classifier", "1", "validation_status", "passed")
# Remove a tag that no longer applies
client.delete_model_version_tag("iris-classifier", "1", "data_snapshot")
mv = client.get_model_version("iris-classifier", "1")
print(mv.tags)The printed tags value is a plain dictionary of strings, here {'validation_status': 'passed'}. Use delete_registered_model_tag for the model level.
Setting tags and a description at creation
Tags set after registration leave a short window in which the version exists without them. If another process loads versions as soon as they appear, it may see an untagged version. Create the version with its metadata in one call to close that window. MlflowClient.create_model_version accepts tags and description.
from mlflow import MlflowClient
client = MlflowClient(tracking_uri="http://127.0.0.1:5000")
run_id = "<run-id-from-the-previous-step>"
mv = client.create_model_version(
name="iris-classifier",
source=f"runs:/{run_id}/model",
run_id=run_id,
description="Retrained after the November data refresh.",
tags={"validation_status": "pending", "data_snapshot": "2026-11-01"},
)
print(mv.name, mv.version, mv.tags)Passing run_id along with the runs:/ source links the version back to the run that produced it. That link is how the UI shows the run's metrics next to the version.
Recording a validation result
The most useful tags are the ones that record a decision, such as validation_status. A small script can evaluate a version and write both the outcome and the evidence to the registry, so a reviewer does not have to reopen the run.
import mlflow
from mlflow import MlflowClient
from sklearn.datasets import load_iris
from sklearn.metrics import accuracy_score
TRACKING_URI = "http://127.0.0.1:5000"
NAME = "iris-classifier"
VERSION = "1"
THRESHOLD = 0.9
mlflow.set_tracking_uri(TRACKING_URI)
client = MlflowClient()
X, y = load_iris(return_X_y=True)
model = mlflow.pyfunc.load_model(f"models:/{NAME}/{VERSION}")
accuracy = accuracy_score(y, model.predict(X))
status = "passed" if accuracy >= THRESHOLD else "failed"
client.set_model_version_tag(NAME, VERSION, "validation_status", status)
client.set_model_version_tag(NAME, VERSION, "validation_accuracy", f"{accuracy:.4f}")
client.set_model_version_tag(NAME, VERSION, "validation_threshold", str(THRESHOLD))
print(status, f"{accuracy:.4f}")This example validates on the training data, which is only acceptable in a demo. A real gate evaluates on held-out data that the model never saw.
Storing the threshold next to the result matters. Later, someone may ask why a version passed. The tags answer the question even if the script has since changed.
A tagging convention
Tags are free-form, so nothing stops two teams from writing validation_status, validated, and ValidationStatus for the same idea. Agree on a small set of keys and values and write it down in the registered model description. A workable starting set:
| Key | Level | Allowed values |
|---|---|---|
| `team` | Registered model | Team name |
| `validation_status` | Version | `pending`, `passed`, `failed` |
| `validation_accuracy` | Version | Decimal string, such as `0.9733` |
| `data_snapshot` | Version | ISO date, such as `2026-11-01` |
| `approved_by` | Version | User or service account name |
Keep the set short. Every key you add is one more thing that automation must set and that reviewers must read.
Gotchas
- Tags are not an access control mechanism. Anyone who can write to the registry can change
validation_status. The server keeps no history of earlier values, so you cannot show that a tag was oncefailed. If you need an audit trail, put the evidence in a run (as metrics and artifacts) and link the version to it, or log changes in your CI system. - Tags do not move with aliases. A tag belongs to a version. If you move the
championalias from version 1 to version 2, the tags stay on their original versions. Read the tags of the version that the alias resolves to, not tags you expect on the alias. - Size limits exist. The server rejects very long keys and values, and the exact limits depend on the MLflow version and backend. Store short facts in tags and put long text in the description or in a run artifact.
- Values are strings. Comparing
"0.9"and"0.85"as strings gives the wrong answer for numeric thresholds. Convert withfloat()before comparing. - Descriptions overwrite. Two processes that update the same description at the same time will lose one of the updates. Keep descriptions for humans, and use tags for anything a script writes.
Exercise
You register version 3 of iris-classifier. Version 2 has the tags validation_status=passed and data_snapshot=2026-10-01. Which tags does version 3 have, and how would you register it so that it never exists without a validation_status tag?
Show answer
Version 3 has no tags, because tags are not inherited from earlier versions or from the registered model. Create it with client.create_model_version(name="iris-classifier", source=f"runs:/{run_id}/model", run_id=run_id, tags={"validation_status": "pending"}). The tag is then part of the creation call, so no reader can see the version without it.
Exercise
A script writes validation_accuracy as a tag, and a reviewer's check does if mv.tags["validation_accuracy"] >= 0.9:. What goes wrong, and how do you fix it?
Show answer
Tag values are strings, so comparing a string with the float 0.9 raises a TypeError in Python 3. Comparing two strings instead would sort them lexicographically and give wrong results for numbers such as "0.85" and "0.9". Convert first with float(mv.tags["validation_accuracy"]) >= 0.9.