Skip to main content

How to Find an MLflow Run by Name

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Run names are what you see in the MLflow UI, but most MLflow functions want a run ID. Searching with attributes.run_name turns one into the other: an exact name, a pattern, or a name in any capitalisation. Names aren't unique, though, so getting "the" run takes one more step. This guide finds runs by name four ways and picks the newest of two runs that share a name, with real results from MLflow 3.18.0.

Syntax​

Syntax
attributes.run_name = '<name>'
attributes.run_name LIKE '<pattern>'
attributes.run_name ILIKE '<pattern>'
PartWhat it means
attributes.run_nameThe run's name, as the runs table shows it. tags.mlflow.runName finds the same runs, because MLflow also stores the name as that tag
= '<name>'Exactly this name, capitalisation included
LIKE '<pattern>'A pattern, where % stands for any number of characters and _ for one
ILIKE '<pattern>'The same, ignoring upper and lower case

Put the name in single quotes, or in double quotes when it contains an apostrophe.

Prerequisites​

Step 1: Create Five Runs​

The example is five runs with an accuracy each: a baseline and its second version, two runs that were both named tuned, and one whose name contains an apostrophe. Create named_runs.py:

named_runs.py
import mlflow

mlflow.set_tracking_uri("http://127.0.0.1:8080")
mlflow.set_experiment("name-search-demo")

for name, accuracy in [
("baseline", 0.80),
("baseline-v2", 0.83),
("tuned", 0.86),
("tuned", 0.89),
("bob's run", 0.70),
]:
with mlflow.start_run(run_name=name):
mlflow.log_metric("accuracy", accuracy)
Terminal
uv run python named_runs.py

It prints a View run link for each of the five runs, two of them called tuned.

Step 2: Search by Name​

Create find_by_name.py. The loop runs four name searches; the last search gets the newest run called tuned:

The find_by_name.py script in a macOS-style code window: a loop over four filters on attributes.run_name, an exact name, LIKE 'baseline%', ILIKE 'BASE%' and a double-quoted name with an apostrophe, printing the matching names, then a search for run_name 'tuned' ordered by start_time DESC with max_results 1 and output_format list, printing the newest run's ID and accuracy.

find_by_name.py
import mlflow

mlflow.set_tracking_uri("http://127.0.0.1:8080")
EXPERIMENT = ["name-search-demo"]

for search in [
"attributes.run_name = 'baseline'",
"attributes.run_name LIKE 'baseline%'",
"attributes.run_name ILIKE 'BASE%'",
"attributes.run_name = \"bob's run\"",
]:
runs = mlflow.search_runs(experiment_names=EXPERIMENT, filter_string=search)
print(f"{search:38} -> {sorted(runs['tags.mlflow.runName'])}")

newest = mlflow.search_runs(
experiment_names=EXPERIMENT,
filter_string="attributes.run_name = 'tuned'",
order_by=["attributes.start_time DESC"],
max_results=1,
output_format="list",
)[0]
print("Newest 'tuned' run:", newest.info.run_id, "accuracy", newest.data.metrics["accuracy"])
Terminal
uv run python find_by_name.py
Output
attributes.run_name = 'baseline' -> ['baseline']
attributes.run_name LIKE 'baseline%' -> ['baseline', 'baseline-v2']
attributes.run_name ILIKE 'BASE%' -> ['baseline', 'baseline-v2']
attributes.run_name = "bob's run" -> ["bob's run"]
Newest 'tuned' run: 0ecfe0ae9bae44ecb0da515a96792898 accuracy 0.89

A terminal running uv run python find_by_name.py: the exact name finds baseline, LIKE 'baseline%' and ILIKE 'BASE%' find baseline and baseline-v2, the double-quoted name finds bob's run, and the newest run called tuned has accuracy 0.89.

Step 3: Read the Results​

  • = 'baseline' found only baseline: = means the whole name, so baseline-v2 doesn't match.
  • LIKE 'baseline%' found both, since % covers -v2.
  • ILIKE 'BASE%' found the same two despite the capitals. = 'Baseline' finds nothing, because = and LIKE match capitalisation exactly.
  • "bob's run" is in double quotes because the name contains an apostrophe. Inside single quotes, neither 'bob''s run' nor 'bob\'s run' finds it.
  • Two runs are called tuned. Sorting by attributes.start_time DESC and keeping one returned the newer, the one with accuracy 0.89, and its run ID.

Common Mistakes​

MistakeWhat happensDo this instead
Assuming a name points to one run= 'tuned' returns two runs hereSort by attributes.start_time DESC and take one, or use the run ID
An apostrophe inside single quotes, 'bob''s run'No match, and no errorUse double quotes: "bob's run"
= for part of a name= 'baseline' misses baseline-v2Use LIKE 'baseline%'

Troubleshooting​

SymptomLikely causeFix
No run found, though the name looks rightCapitalisation or a space differsUse ILIKE, or copy the name from the runs table
The run you want isn't in the resultsIt's in another experiment, or deletedCheck experiment_names, and see How to Include Deleted Runs in an MLflow Search in Python

FAQ​

How do I get a run's ID from its name in the UI?​

Search attributes.run_name = '<name>' in the runs table's search box and open the run: its ID is on the run page and in the page's address.

Is run_name the same as the mlflow.runName tag?​

They hold the same name: tags.mlflow.runName = 'tuned' returned the same two runs as attributes.run_name = 'tuned'.

Can I make run names unique?​

MLflow doesn't enforce it. A naming scheme that includes something unique, such as a date or a seed, avoids duplicates.

Conclusion​

attributes.run_name = '<name>' found runs by exact name, LIKE and ILIKE by pattern, and double quotes handled a name with an apostrophe. Because names repeat, order_by=["attributes.start_time DESC"] with max_results=1 turned a name into the newest run's ID.

Additional Resources​