Sub topic 3
How Unity Catalog names and organizes models
This chapter assumes you know what catalogs, schemas and tables are in Unity Catalog, and that you can run Python in a Databricks notebook. It covers how a registered model gets its name and where it sits in the hierarchy. The next chapters cover the registration step itself.
Models are schema-level objects
Unity Catalog is the governance layer for a Databricks account. It arranges data and AI assets in a fixed hierarchy:
- A metastore is the top-level container. It is attached to one or more workspaces.
- A catalog groups related schemas, often by environment or team.
- A schema (also called a database) groups objects inside a catalog.
- A registered model is one of the objects a schema can hold, next to tables, views, volumes and functions.
- A model version is an immutable snapshot of a registered model.
Because models live in the same hierarchy as tables, they use the same access control, auditing and lineage as your data.
The three-level name
A registered model is identified by a three-level name:
<catalog>.<schema>.<model>For example, main.default.iris_classifier is the model iris_classifier in the default schema of the main catalog. The tutorial uses this name throughout.
The older Workspace Model Registry used flat names such as iris_classifier, and it was scoped to a single workspace. A Unity Catalog model belongs to the metastore. Any workspace attached to that metastore can reach it, subject to privileges.
Pointing MLflow at Unity Catalog
MLflow talks to the legacy workspace registry unless you tell it otherwise. Set the registry URI before you log or load models:
import mlflow
from mlflow import MlflowClient
mlflow.set_registry_uri("databricks-uc")
client = MlflowClient()
model_name = "main.default.iris_classifier"
catalog, schema, model = model_name.split(".")
print(f"catalog={catalog} schema={schema} model={model}")
# Works once the model has been registered (next chapter)
registered = client.get_registered_model(model_name)
print(registered.name)The split line shows that the name is just three parts joined by dots. Every MLflow call that takes a model name, including models:/main.default.iris_classifier@champion URIs, expects the full three-part form.
Creating a place for models
A model needs an existing catalog and schema. You can use main.default, but a dedicated schema keeps models apart from tables and makes permissions easier to reason about:
CREATE SCHEMA IF NOT EXISTS main.ml_models
COMMENT 'Registered models for the data science team';The model would then be main.ml_models.iris_classifier. A common convention is one catalog per environment (dev, staging, prod) with the same schema and model names in each. Promoting a model then means copying it to a different catalog.
Naming rules and common errors
- Use all three parts. A name like
iris_classifierfails, because MLflow cannot tell which catalog and schema you mean. The usual symptom is an error about the registry or a missing name part. - Names are lowercase. Unity Catalog stores object names in lowercase, so avoid names that differ only by case.
- Avoid periods, spaces and slashes inside a part. A period is the separator, so it cannot appear within a catalog, schema or model name. Use underscores instead.
- Set the registry URI first. If you forget
set_registry_uri("databricks-uc"), MLflow may try to register a three-part name in the legacy registry and fail. - Check that the schema exists. Registering into a schema that does not exist fails. Registering into one you cannot write to fails with a permission error. Privileges are covered in a later chapter.
Exercise
A teammate runs mlflow.sklearn.log_model(model, "model", registered_model_name="churn_model") after calling mlflow.set_registry_uri("databricks-uc"), and it fails. What is the likely cause, and what would you change?
Show answer
Unity Catalog requires a three-level name, and churn_model has only one part. Change it to <catalog>.<schema>.churn_model, for example main.ml_models.churn_model. The catalog and schema must already exist, and the user needs privileges to create models in that schema.