Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Mlflow Mlflow Set Model Version Tag

From Leeroopedia
Knowledge Sources
Domains ML_Ops, Model_Management
Last Updated 2026-02-13 20:00 GMT

Overview

Concrete tools for managing model version lifecycle metadata through tags and aliases provided by the MLflow library.

Description

MLflow exposes two complementary APIs for annotating registered model versions:

mlflow.set_model_version_tag attaches an arbitrary key-value tag to a specific version of a registered model. Tags are useful for classification, provenance, and operational metadata that may evolve independently of the model artifact itself.

MlflowClient.set_registered_model_alias assigns a named pointer (alias) to a model version. Aliases such as "champion", "production", or "staging" allow downstream consumers to reference a model by role rather than by version number, enabling seamless promotion and rollback. Note that aliases of the format v<number> (e.g., v9, v42) are reserved and cannot be used.

Together these two functions cover the metadata and routing dimensions of model version governance.

Usage

Use set_model_version_tag to annotate versions with metadata such as approval status, owning team, dataset provenance, or evaluation results. Use set_registered_model_alias to assign or reassign environment-level pointers that downstream serving and scoring systems consume.

Code Reference

Source Location

  • Repository: mlflow
  • File (tag): mlflow/tracking/_model_registry/fluent.py
  • Lines (tag): 533-553
  • File (alias): mlflow/tracking/client.py
  • Lines (alias): 5440-5527

Signature

# Set a tag on a model version
def set_model_version_tag(
    name: str,
    version: str | None = None,
    key: str | None = None,
    value: Any = None,
) -> None

# Set an alias pointing to a model version
def set_registered_model_alias(
    name: str,
    alias: str,
    version: str,
) -> None

Import

import mlflow
from mlflow import MlflowClient

I/O Contract

Inputs

Name Type Required Description
name str Yes The name of the registered model.
version str Yes (for tag); Yes (for alias) The version number of the registered model to tag or to which the alias should point.
key str Yes (for tag) The tag key to set on the model version.
value Any Yes (for tag) The tag value to set on the model version.
alias str Yes (for alias) The alias name to assign (e.g., "production", "staging"). Aliases matching v<number> are reserved.

Outputs

Name Type Description
return value (tag) None The function sets the tag as a side effect and returns nothing.
return value (alias) None The function sets the alias as a side effect and returns nothing.

Usage Examples

Basic Usage

import mlflow
from mlflow import MlflowClient

model_name = "RandomForestRegressionModel"
model_version = "1"

# Set tags on the model version
mlflow.set_model_version_tag(
    name=model_name,
    version=model_version,
    key="validation_status",
    value="approved",
)
mlflow.set_model_version_tag(
    name=model_name,
    version=model_version,
    key="dataset",
    value="production_v3",
)

# Set an alias so consumers can load by role instead of version number
client = MlflowClient()
client.set_registered_model_alias(
    name=model_name,
    alias="champion",
    version=model_version,
)

# Downstream consumers can now load via:
#   mlflow.pyfunc.load_model("models:/RandomForestRegressionModel@champion")

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment