Sub topic 4
Registering a model in Unity Catalog
This chapter covers the step that turns a logged MLflow model into a governed, versioned asset in Unity Catalog. It assumes you already know the following:
- You can train a scikit-learn style model and call
predict. - You know that MLflow can log a model together with a signature (a declared schema for inputs and outputs).
- You know that Unity Catalog names objects as
catalog.schema.object.
By the end you should be able to register a model in one step or two, check what was created, and diagnose the most common registration failures.
What registration adds
Logging a model saves it as an artifact (a stored file set) inside an MLflow run. The run is a record of one training execution. Anyone who can read the run can load the model by its runs:/<run_id>/model URI. That URI is awkward to share and carries no permissions or version history of its own.
Registering a model creates an entry in a registry. In Unity Catalog, that entry is a registered model, a securable object that lives in a schema. Each registration adds a new model version to it. Registration gives you three things:
- A stable, human-readable name, such as
main.default.iris_classifier. - Numbered versions that point back to the run that produced them.
- Access control through Unity Catalog privileges, the same system that governs your tables.
Model Serving and batch inference jobs consume registered model versions, not raw run artifacts. Registration is the hand-off point between training and deployment.
Choosing the Unity Catalog registry
MLflow supports two registries on Databricks. The older workspace model registry is local to one workspace. The Unity Catalog registry is shared across every workspace attached to the same metastore, and it is the one this tutorial uses.
You choose the registry with the registry URI:
import mlflow
mlflow.set_registry_uri("databricks-uc")Call this before any logging or registering code. If you skip it, MLflow may send the request to the workspace registry. That registry rejects a three-level name, or it silently creates the model in the wrong place. Some newer Databricks runtimes default to Unity Catalog. Setting the URI explicitly costs one line and removes the doubt.
The name you register under
A Unity Catalog model name has three parts joined by dots:
| Part | Example | What it is |
|---|---|---|
| Catalog | `main` | The top-level container, often one per environment or team |
| Schema | `default` | A namespace inside the catalog |
| Model | `iris_classifier` | The registered model itself |
The full name is main.default.iris_classifier. Two rules cause most naming errors:
- The name must have all three parts.
iris_classifieralone is a valid workspace-registry name but not a valid Unity Catalog name. - The catalog and schema must already exist. Registration creates the model, not its parents.
Names are lowercase by convention. Avoid spaces, periods and slashes inside a part. If you must use unusual characters, expect to quote them with backticks in SQL.
Registering in one step
The simplest path logs and registers in the same call. Pass registered_model_name to log_model:
import mlflow
from mlflow.models import infer_signature
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
# Use Unity Catalog as the model registry
mlflow.set_registry_uri("databricks-uc")
X, y = load_iris(return_X_y=True, as_frame=True)
model = RandomForestClassifier(n_estimators=50, random_state=0).fit(X, y)
# Unity Catalog requires a signature for registered models
signature = infer_signature(X, model.predict(X))
with mlflow.start_run():
mlflow.sklearn.log_model(
model,
artifact_path="model",
signature=signature,
input_example=X.head(5),
registered_model_name="main.default.iris_classifier",
)When this runs, MLflow does the following:
- It creates a run, or uses the active one, and uploads the model files as an artifact.
- It checks whether
main.default.iris_classifierexists. If it does not, MLflow creates it. - It creates a new model version that points at the logged artifact.
If you run the cell again, the model already exists, so step 2 is skipped and you get version 2. Each run of this code adds a version. That is useful for tracking and wasteful if you run the cell by accident dozens of times.
The signature is not optional here. Unity Catalog refuses to register a model that has no signature. infer_signature builds one from sample inputs and the model's outputs. The input_example is not required for registration, but it lets MLflow validate the model and gives serving a ready-made test payload.
Registering in two steps
Sometimes you log first and decide later whether the model deserves registration. For example, you may train twenty candidates and register only the best. In that case, log without registered_model_name, keep the run ID, and register afterward:
import mlflow
from mlflow import MlflowClient
mlflow.set_registry_uri("databricks-uc")
# run_id comes from the run that logged the model
run_id = "<run-id-of-the-best-run>"
result = mlflow.register_model(
model_uri=f"runs:/{run_id}/model",
name="main.default.iris_classifier",
)
print("Created version", result.version)
client = MlflowClient()
version = client.get_model_version(
name="main.default.iris_classifier",
version=result.version,
)
print(version.status, version.run_id)The model_uri has the form runs:/<run_id>/<artifact_path>. The artifact path must match the one you used when logging, which was "model" in the example above. A mismatch produces a "no such artifact" style error, not a naming error.
register_model returns a ModelVersion object. Its version field is the integer assigned by Unity Catalog. Registration copies the model files into storage managed by Unity Catalog, so a version can take several seconds to reach the READY status. Check status before you try to serve or load a fresh version in the same script.
The flow below shows both paths ending in the same state.
Inspecting what you created
After registering, confirm the result instead of assuming it. You can list versions from code:
from mlflow import MlflowClient
import mlflow
mlflow.set_registry_uri("databricks-uc")
client = MlflowClient()
for mv in client.search_model_versions("name='main.default.iris_classifier'"):
print(mv.version, mv.status, mv.run_id)Unity Catalog supports filtering by exact name only. Filters on tags or run IDs that work in the workspace registry are not available here, so filter the returned list in Python if you need them.
You can also see the model in Catalog Explorer in the workspace. Open the catalog, then the schema, and look under Models. Each version page shows its run, its signature and its creation time.
What registration requires from you
Registration fails unless your identity holds the right privileges. For a new model, you need all of these:
USE CATALOGon the parent catalog.USE SCHEMAon the parent schema.CREATE MODELon the schema.
To add a new version to an existing model, you generally need to own that model, or hold privileges that allow it. Being able to read a model does not let you add versions to it. The next chapters cover granting privileges for other users in detail. The key point here is that a training job running as a service principal needs the same privileges as a person. A job that registered fine under your user account may fail under a service principal that has not been granted CREATE MODEL.
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| Error about missing signature metadata | The model was logged without a `signature` | Add `signature=infer_signature(X, preds)` and log again |
| Name is rejected or parsed oddly | Only one or two name parts were given, or the workspace registry is active | Use `catalog.schema.model` and call `set_registry_uri("databricks-uc")` |
| Schema or catalog not found | The parent object does not exist or is misspelled | Create it, or fix the name; check with `SHOW SCHEMAS IN main` |
| Permission denied on create | Missing `CREATE MODEL`, `USE SCHEMA` or `USE CATALOG` | Ask an owner to grant the missing privilege |
| Permission denied on a new version of an existing model | You do not own the model | Have the owner register, or transfer ownership to a shared group |
| Artifact not found during `register_model` | `runs:/` URI uses the wrong run ID or artifact path | Match the `artifact_path` used at logging time |
| Version stuck in a pending state | Model files are still being copied | Poll `get_model_version` until the status is `READY` |
Practical habits
- Own models with a group. The creator becomes the owner. If that is an individual who leaves, you may have to ask an admin to reassign it. Create models while running as a team-owned service principal, or transfer ownership to a group early.
- Register deliberately. Each call adds a version, and versions are never edited. Automate registration from a pipeline's final step, not from every exploratory run.
- Keep the run link. Every version records its source run. That link is how you trace a deployed model back to its training parameters, metrics and code, so do not delete runs you still serve from.
- Do not use stages. The workspace registry had
StagingandProductionstages. Unity Catalog does not. It uses aliases, which the next chapter covers.
Exercise
A teammate runs mlflow.sklearn.log_model(model, artifact_path="model", registered_model_name="iris_classifier") after mlflow.set_registry_uri("databricks-uc"). The call fails. Give two separate changes that would be needed for it to succeed, assuming the catalog main and schema default exist and the teammate has all required privileges.
Show answer
First, the name must be fully qualified: main.default.iris_classifier. Second, the call must include a signature, for example signature=infer_signature(X, model.predict(X)), because Unity Catalog does not register models without one.
Exercise
You logged several candidate models without registering them and now want to register only the run with ID abc123, whose artifact path was "model". Write the call, and explain how you can check that the new version is ready to use.
Show answer
mlflow.register_model(model_uri="runs:/abc123/model", name="main.default.iris_classifier"). The returned ModelVersion has a version number. Call MlflowClient().get_model_version(name, version) and check that status is READY before loading or serving the version.