Sub topic 14
Organizing experiments and controlling access
This chapter assumes you can log runs with mlflow.start_run, set an experiment by path, and read a run in the experiment UI. It covers how to arrange experiments so a team can find them, and how to control who can read, write, or manage them.
Why organization and access matter
One person's experiments are easy to find. A team's are not. After a few months, a workspace can hold hundreds of experiments called Untitled, test2, or the name of a notebook someone has since renamed. Runs in them may hold training data statistics or customer-derived features, so some should not be visible to everyone.
You solve both problems with three things:
- A path convention for experiments.
- Tags on experiments, so you can search by team or project.
- Permissions, set on experiments or on the folders that contain them.
Where an experiment lives decides who sees it
On Databricks, an experiment is either a notebook experiment or a workspace experiment. Their access models differ.
| Property | Notebook experiment | Workspace experiment |
|---|---|---|
| Created | Automatically on the first run in a notebook, if you don't call `set_experiment` | By `mlflow.set_experiment(path)` or in the UI |
| Location | Tied to the notebook | A path in the workspace file tree |
| Access control | Follows the notebook's permissions | Its own permissions, plus those of the parent folder |
| Best for | Quick exploration by one person | Shared work, jobs, and anything you need to find again |
Notebook experiments are easy to lose track of because they move with the notebook. If you move or delete the notebook, finding the runs becomes harder. For anything a team will return to, use a workspace experiment with an explicit path.
Choosing a path convention
The experiment path is a workspace path, so you can use folders. Two common roots are:
/Users/<your-email>/...for personal work. Only you and workspace admins can see it by default./Workspace/Shared/...for team work. Wider access is possible, but you should still restrict it deliberately.
A convention that scales is <root>/<team-or-project>/<model-or-task>. For example:
/Workspace/Shared/fraud-detection/transaction-classifier
/Workspace/Shared/fraud-detection/feature-selection
/Users/<your-email>/scratch/iris-trackingPut one experiment per model or task, not one per run attempt. Within an experiment, use run names, tags, and nested runs to distinguish trials. Hundreds of experiments with one run each defeat the comparison view.
Tagging experiments
Runs have tags, and so do experiments. Experiment tags let you filter experiments without relying on path alone. The next example sets tags and then searches by them.
import mlflow
from mlflow import MlflowClient
experiment_path = "/Users/<your-email>/iris-tracking"
mlflow.set_experiment(experiment_path)
client = MlflowClient()
experiment = mlflow.get_experiment_by_name(experiment_path)
client.set_experiment_tag(experiment.experiment_id, "team", "ml-platform")
client.set_experiment_tag(experiment.experiment_id, "lifecycle", "active")
matches = mlflow.search_experiments(
filter_string="tags.team = 'ml-platform'",
max_results=20,
)
for exp in matches:
print(exp.experiment_id, exp.name)mlflow.search_experiments returns Experiment objects. Its filter syntax is similar to search_runs, and tags are addressed as tags.<key>.
Pick a small set of tag keys, such as team, project, and lifecycle, and use them everywhere. Free-form tags drift quickly, and Team, team, and squad end up meaning the same thing.
Permission levels
Databricks assigns permissions on an experiment to users, groups, or service principals. There are three working levels.
| Level | What it allows |
|---|---|
| CAN READ | View runs, parameters, metrics, tags, and artifacts. Compare runs. |
| CAN EDIT | Everything in CAN READ, plus logging new runs and editing or deleting runs. |
| CAN MANAGE | Everything in CAN EDIT, plus renaming or deleting the experiment and changing its permissions. |
A person with no entry has no access, unless a parent folder grants it. The creator of an experiment has CAN MANAGE on it, and workspace admins can manage any experiment.
Assign permissions to groups, not individuals. When someone joins or leaves the team, you change group membership once, and no experiment needs editing.
Inheritance from folders
Workspace experiments inherit permissions from the folder that holds them. If you grant a group CAN READ on /Workspace/Shared/fraud-detection, the group can read every experiment inside it, including ones created later. That is why the path convention matters: the folder structure becomes your access structure.
When you need a stricter setup for one experiment, check the folder first. A restrictive grant on the experiment may not help if the folder is already open to a broad group.
Setting permissions from code
You can set permissions in the experiment UI through the Permissions button. For repeatable setups, such as a project template or a deployment script, use the Databricks SDK for Python. This example grants a group read access and another group edit access. It adds to the existing permissions and does not replace them.
import mlflow
from databricks.sdk import WorkspaceClient
from databricks.sdk.service.ml import (
ExperimentAccessControlRequest,
ExperimentPermissionLevel,
)
experiment_path = "/Users/<your-email>/iris-tracking"
experiment = mlflow.get_experiment_by_name(experiment_path)
w = WorkspaceClient()
w.experiments.update_permissions(
experiment_id=experiment.experiment_id,
access_control_list=[
ExperimentAccessControlRequest(
group_name="data-science-readers",
permission_level=ExperimentPermissionLevel.CAN_READ,
),
ExperimentAccessControlRequest(
group_name="data-science-engineers",
permission_level=ExperimentPermissionLevel.CAN_EDIT,
),
],
)Use update_permissions to patch the list. set_permissions replaces the entire list, so it will remove existing grants that you don't repeat. That can lock out people who had access.
Common errors
- A job fails with a permission error when logging. The job runs as a user or service principal. That identity needs CAN EDIT on the experiment, or on its parent folder. Check which identity runs the job, not which user wrote the code.
set_experimentcreates an experiment in an unexpected place. If the path is wrong, MLflow may create a new experiment instead of finding yours. Printmlflow.get_experiment_by_name(path)first if you expect it to exist.- A teammate can't see your experiment under
/Users/. Personal folders are private by default. Move the experiment to a shared folder, or grant access on it explicitly. - Runs vanish after someone clears out the experiment. CAN EDIT includes deleting runs. If runs are an audit record, give most people CAN READ and keep CAN EDIT for the jobs that log.
- Someone deleted an experiment and wants it back. Deletion is a soft delete, but restoring it requires someone who can manage it. Limit CAN MANAGE to a small group.
Models have their own access control
Experiment permissions do not cover registered models. A model registered in Unity Catalog follows Unity Catalog privileges, such as USE CATALOG and USE SCHEMA on its parents, CREATE MODEL to register in a schema, and EXECUTE to load and use a model. A person with CAN READ on an experiment can see the logged model artifacts of a run. They still need the right Unity Catalog privileges to register the model or to load a registered version.
Plan both layers together. Data scientists usually get CAN EDIT on the project's experiments. They also get CREATE MODEL on a development schema. A separate, smaller group, or an automated service principal, gets write privileges on the production schema.
A checklist for a new project
- Choose a folder such as
/Workspace/Shared/<project>and grant groups access on the folder. - Create experiments with
mlflow.set_experimentand an absolute path, one per model or task. - Add experiment tags for
team,project, andlifecycle. - Give people CAN READ by default, and CAN EDIT only to those who log runs.
- Keep CAN MANAGE for a small owner group.
- Check that job identities have CAN EDIT and the Unity Catalog privileges they need.
Exercise
A scheduled job runs as a service principal and fails to log runs to /Workspace/Shared/fraud-detection/transaction-classifier. The data science group has CAN EDIT on that folder. What is the most likely cause, and how do you fix it without using the group?
Show answer
The job identity is the service principal, not a member of the data science group, so it inherits no access from the group's grant. Grant the service principal CAN EDIT on the experiment or on the parent folder, for example with w.experiments.updatepermissions and an ExperimentAccessControlRequest that sets serviceprincipalname and CANEDIT. Use update_permissions so existing grants are kept.
Exercise
You call w.experiments.setpermissions with a list that contains only one group with CANREAD. What happens to the other users and groups that had access before, and what should you have called?
Show answer
Their grants are removed, because setpermissions replaces the whole access control list. You should have called updatepermissions, which adds or changes only the entries you pass.