Skip to main content

How to Add Tags to a Model Version in MLflow

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

A model version can carry facts about itself: whether it passed review, who reviewed it, which ticket it belongs to. MLflow stores them as tags, key and value pairs on the version. This guide sets a tag when a version is registered, changes it, adds another and deletes one, with real output from MLflow 3.18.0.

Syntax​

Syntax
version = mlflow.register_model(model_uri, name, tags={key: value})
client = MlflowClient()
client.set_model_version_tag(name, version_number, key, value)
client.delete_model_version_tag(name, version_number, key)
client.get_model_version(name, version_number).tags
PartWhat it means
tags={key: value}Tags the new version gets as it's registered
nameThe registered model
version_numberThe version's number, such as "1" or version.version
key, valueThe tag's name and its value; setting a key that exists replaces its value
.tagsA dictionary of the version's tags

MLflow's Model Registry workflows page sets and deletes a version tag with exactly these calls: client.set_model_version_tag("example-model", "1", "validation_status", "approved").

Prerequisites​

  • An MLflow tracking server with a database backend at http://127.0.0.1:8080, such as mlflow server --port 8080 with its default SQLite database. The registry needs one.
  • mlflow and scikit-learn in your project, for example with uv add mlflow scikit-learn pandas.

Step 1: Tag a Version, Change the Tag, Delete One​

The example logs a breast cancer classifier and registers it as tumour-screening, with validation_status set to pending. After a review, it sets the status to approved and adds a reviewed_by tag, then deletes reviewed_by again, printing the version's tags at each point:

The version_tags.py script in a macOS-style code window: a breast cancer classifier logged and registered as tumour-screening with tags validation_status pending, then set_model_version_tag to approved and reviewed_by data-science, then delete_model_version_tag reviewed_by, printing the tags after each step.

version_tags.py
import mlflow
from mlflow import MlflowClient
from sklearn.datasets import load_breast_cancer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

mlflow.set_tracking_uri("http://127.0.0.1:8080")
mlflow.set_experiment("version-tags-example")
client = MlflowClient()
name = "tumour-screening"

X, y = load_breast_cancer(return_X_y=True, as_frame=True)
y = y == 0 # True when the tumour is malignant
model = make_pipeline(StandardScaler(), LogisticRegression()).fit(X, y)
with mlflow.start_run():
info = mlflow.sklearn.log_model(model, name="model", input_example=X.head(3))

# A tag can be set when the version is created...
version = mlflow.register_model(info.model_uri, name, tags={"validation_status": "pending"})
print("At registration:", client.get_model_version(name, version.version).tags)

# ...and changed or added later.
client.set_model_version_tag(name, version.version, "validation_status", "approved")
client.set_model_version_tag(name, version.version, "reviewed_by", "data-science")
print("After review: ", client.get_model_version(name, version.version).tags)

client.delete_model_version_tag(name, version.version, "reviewed_by")
print("After delete: ", client.get_model_version(name, version.version).tags)
Terminal
uv run python version_tags.py
Output (last lines)
At registration: {'validation_status': 'pending'}
After review: {'validation_status': 'approved', 'reviewed_by': 'data-science'}
After delete: {'validation_status': 'approved'}

The end of the output in a terminal: at registration validation_status is pending, after review it is approved with reviewed_by data-science, and after the delete only validation_status approved is left.

  • At registration: the tag came with the new version, so it never existed without a status.
  • After review: setting validation_status again replaced pending with approved, and reviewed_by was added beside it.
  • After delete: reviewed_by is gone and the status stays.

Common Mistakes​

MistakeWhat happensDo this instead
Using a tag to choose which version code loadsCode has to search for the tag, and two versions can carry the same valueUse an alias, which points to one version at a time
Setting a registered model tag when you meant the versionThe tag describes the whole model, not this versionUse set_model_version_tag for facts about one version

Troubleshooting​

SymptomLikely causeFix
RESOURCE_DOES_NOT_EXIST: Model Version (name=tumour-screening, version=9) not foundThe version number doesn't existUse the number from register_model's result, or the registered model's page
The tag value comes back as a stringMLflow stores tag values as stringsConvert it when you read it, such as with int(...)

FAQ​

Can I find versions by their tags?​

Yes, with a filter such as tags.validation_status = 'approved': How to Search Model Versions in MLflow.

How is this different from a run's tags?​

A run's tags describe the training run; a version's tags describe the registered version. They're separate: How to Add Tags to an MLflow Run covers the run's.

Conclusion​

register_model(..., tags={"validation_status": "pending"}) tagged version 1 of tumour-screening as it was created, set_model_version_tag changed and added tags after the review, and delete_model_version_tag removed one.

Additional Resources​