Sub topic 14
Automating Promotion Gates and Controlling Access
This chapter assumes that you understand MLflow experiments, runs, registered models, versions, tags, and aliases. It also assumes that a tracking server is already running and that your client can read and update the registry.
A promotion gate is a rule that must pass before a model version receives a production alias. For example, a gate might require:
- A validation tag with the value
passed. - A minimum accuracy recorded in the source run.
- A model signature.
- Approval from a reviewer or deployment job.
The registry stores model metadata, but it does not decide whether your organization’s gate has passed. Your pipeline must inspect the version, apply the rules, and assign the alias only after every rule succeeds.
A promotion gate in Python
The following script promotes only versions that have a validation_status tag set to passed and a source-run accuracy of at least 0.90.
import os
import mlflow
from mlflow import MlflowClient
tracking_uri = os.environ.get(
"MLFLOW_TRACKING_URI",
"http://127.0.0.1:5000",
)
model_name = os.environ.get("MODEL_NAME", "iris-classifier")
version = os.environ["MODEL_VERSION"]
minimum_accuracy = 0.90
mlflow.set_tracking_uri(tracking_uri)
client = MlflowClient()
model_version = client.get_model_version(model_name, version)
status = model_version.tags.get("validation_status")
if status != "passed":
raise RuntimeError(
f"Version {version} has validation_status={status!r}"
)
if not model_version.run_id:
raise RuntimeError("The model version has no source run")
run = client.get_run(model_version.run_id)
accuracy = run.data.metrics.get("accuracy")
if accuracy is None or accuracy < minimum_accuracy:
raise RuntimeError(
f"Accuracy gate failed: {accuracy!r} < {minimum_accuracy}"
)
client.set_registered_model_alias(
model_name,
"champion",
version,
)
print(f"{model_name} version {version} is now champion")The script fails closed. A missing tag or metric prevents promotion instead of being treated as success. Store the required validation result on the model version, and store measurements such as accuracy on the source run.
A production pipeline should also check that the model has the expected input signature, that required artifacts exist, and that tests have passed. Keep these checks deterministic and record their results so that another person can audit the decision.
Separating environments and permissions
A small team can use one registered model and promote versions with aliases. Larger teams often separate development, staging, and production registered models:
- Developers can create versions in a development registry.
- A validation job can copy an approved version into staging.
- A release job can copy the approved staging version into production.
- Production consumers receive permission to read models, but not to change aliases.
Use your MLflow deployment’s authentication and authorization features, or place the tracking server behind an identity-aware gateway. Grant the narrowest permissions needed for each role. The exact permission names depend on the hosting platform and MLflow distribution.
Auditing and repeatability
Treat promotion as a change that must be traceable. Record the validation job identifier, reviewer, test-suite version, and deployment timestamp as model-version tags. Do not overwrite a failed result with a passing result without preserving the original evidence in your pipeline system.
For repeatable automation, make the gate idempotent. Running it twice with the same approved version should produce the same alias assignment. Before changing the alias, compare the current champion with the requested version and log both values.
Exercise
Exercise
Why should a missing validation tag fail the promotion gate instead of being ignored?
Show answer
Ignoring it could promote a version that was never validated. Failing closed requires explicit evidence before production changes.