In the MLflow registry, how do you record a validation result and a reviewer's sign-off on a `room-rate-staging` version, and find the versions that passed?
answer
- labels, not pointers
- a version's tags versus the model's tags
- set_model_version_tag(name, version, key, value)
- tags.<key> in a filter string
- search results may lack aliases
basics
~10 sSet model version tags with MlflowClient.set_model_version_tag, for example validation_status=passed and approved_by=<reviewer>, and find them with search_model_versions using a filter such as name = 'room-rate-staging' and tags.validation_status = 'passed'.
solid answer
~40 sStatus that belongs to one build goes in **model version tags**: `client.set_model_version_tag("room-rate-staging", "21", "validation_status", "passed")`, then `approved_by` with the reviewer's id once the review is done. Facts about the model as a whole, such as its task or owning team, go in **registered model tags** via `set_registered_model_tag`. A deploy job finds candidates with `client.search_model_versions("name = 'room-rate-staging' and tags.validation_status = 'passed'", order_by=["version_number DESC"])`. Tags are many-to-many labels: any number of versions can carry `validation_status=passed`, unlike an alias, which names one version. They record a decision; they do not enforce one, because anyone allowed to edit the model can set them. `register_model(..., tags=...)` sets tags at registration, and `copy_model_version` carries a version's tags to the copy.
code
python · 18 linesfrom mlflow import MlflowClient
client = MlflowClient(tracking_uri="http://mlflow.internal.example:5000")
name, version = "room-rate-staging", "21"
# Record the check and the sign-off on this one version
client.set_model_version_tag(name, version, "validation_status", "passed")
client.set_model_version_tag(name, version, "approved_by", "reviewer-042")
# A fact about the model as a whole
client.set_registered_model_tag(name, "task", "nightly-room-rate")
# Newest versions that passed validation
passed = client.search_model_versions(
"name = 'room-rate-staging' and tags.validation_status = 'passed'",
order_by=["version_number DESC"],
)
print([mv.version for mv in passed])go deeper
Recall that the registry has key-value tags on versions and on registered models, and that validation_status is the usual example.
Show the calls, set_model_version_tag versus set_registered_model_tag, and write a search_model_versions filter on tags.<key> with an order_by.
Explain why approval is a tag and not an alias, that tags record without enforcing, and that copy_model_version carries them across registered models.
Decide which facts live in registry tags and which in an external audit log, given that a tag holds only its latest value and is writable by any editor.
## Two kinds of registry tag The MLflow Model Registry has **key-value tags** at two levels: - **Model version tags** describe one version: whether it passed validation, who reviewed it, which data snapshot trained it. Set with `MlflowClient.set_model_version_tag(name, version, key, value)` and removed with `delete_model_version_tag(name, version, key)`. - **Registered model tags** describe the model as a whole: its task, the owning team, the business domain. Set with `set_registered_model_tag(name, key, value)` and removed with `delete_registered_model_tag(name, key)`. The registry docs use exactly this split, showing `validation_status:pending` while a version is being validated and `validation_status:approved` once it clears. When registry stages were deprecated, model version tags were the named replacement for "this version is in Staging" as a status. ## Recording a check and a sign-off For the nightly room-rate model, a validation job and a human review leave a trail on the version: 1. On registration, pass initial tags: `mlflow.register_model(uri, "room-rate-staging", tags={"validation_status": "pending"})`. 2. The validation job finishes and calls `set_model_version_tag("room-rate-staging", "21", "validation_status", "passed")`, or `"failed"`. 3. The reviewer, or the tool they approve in, sets `approved_by` to their id and, if useful, `approved_at` to a timestamp. 4. Only then does someone move an alias, which is a separate call and a separate record. Setting a tag key that already exists replaces its value, so a version shows only the latest value of each key. If the sequence of states matters, keep it in your own audit log or the job's run; the tag is the current state. ## Finding the versions that passed `MlflowClient.search_model_versions(filter_string, max_results, order_by, page_token)` accepts these identifiers: | Identifier | Meaning | Comparators | |---|---|---| | `name` | registered model name | `=`, `!=`, `LIKE`, `ILIKE` | | `run_id` | run that produced the version | the same, plus `IN` | | `source_path` | version source path | `=`, `!=`, `LIKE`, `ILIKE` | | `tags.<key>` | a model version tag | `=`, `!=`, `LIKE`, `ILIKE` | Clauses combine with `AND`. A tag key with spaces is wrapped in backticks. `order_by` accepts `name`, `version_number`, `creation_timestamp` and `last_updated_timestamp` with `ASC` or `DESC`, so `order_by=["version_number DESC"]` puts the newest passing version first. Registered models have their own `search_registered_models` with `name` and `tags.<key>`. One warning from the client's docstring: **search results may not have aliases populated** for performance reasons. To learn which version is `champion`, ask `get_model_version_by_alias`, not the search. ## Tags against aliases - An **alias** names exactly one version and is what a consumer loads (`models:/room-rate-prod@champion`). - A **tag** can sit on any number of versions and is never part of a load URI. - Use tags for "what is true of this build" and aliases for "which build to use". ## Conventions that keep tags queryable - **Fix the key vocabulary.** `validation_status`, `approved_by`, `data_snapshot`: one spelling, written by code, so a filter string never misses a `ValidationStatus` written by hand. - **Use a small set of values.** `pending`, `passed`, `failed` filter cleanly with `=`; free text forces `LIKE` patterns. - **Avoid spaces in keys.** A key with spaces must be wrapped in backticks in every filter string. - **Write tags from the job that knows the fact.** The validation job sets `validation_status`; a human sets only what a human decided. ## What a tag does not prove - A tag is a string anyone with edit permission on the model can write. `approved_by=reviewer-042` records that someone wrote it; whether that person had the authority, and what an approval must demonstrate, belongs to the promotion process, not the registry API. - Tags do not block anything. A deploy step that should refuse unvalidated versions must check the tag itself, or check it in CI before calling `set_registered_model_alias`. - `copy_model_version` copies version tags to the new version, so a `validation_status` set in staging travels into production unless you reset it there.
- Why not record approval by giving the version an alias such as `approved`?An alias can name only one version per registered model, so setting `approved` on version 22 silently takes it off 21. Approval is true of many versions at once, which is a tag's shape. Keep aliases for the single version a consumer should load.
- Can `search_model_versions` filter on a registered model tag such as `task`?No. In `search_model_versions`, `tags.<key>` means a model version tag. Registered model tags are filtered with `search_registered_models`, which accepts `name` and `tags.<key>` for the registered model's own tags.
- A validation_status tag stops an unvalidated version from being loaded or served.
- Model version tags and registered model tags are the same store, set by one call.
- Tagging a version approved also moves the champion alias onto it.
- search_model_versions results always list each version's aliases.
- Re-setting a tag key keeps the old value alongside the new one as history.