Implementation:Mlflow Mlflow Set Prompt Alias
| Knowledge Sources | |
|---|---|
| Domains | ML_Ops, Prompt_Engineering |
| Last Updated | 2026-02-13 20:00 GMT |
Overview
Concrete tool for assigning and removing human-readable aliases on prompt versions in the MLflow Prompt Registry, provided by the MLflow library.
Description
The mlflow.genai.set_prompt_alias() function assigns a named alias (such as "production" or "staging") to a specific version of a registered prompt. Once set, the alias can be used in URI-based loading with the @ notation (e.g., prompts:/my_prompt@production). If the alias already exists on another version, it is moved to the newly specified version.
The companion mlflow.genai.delete_prompt_alias() function removes an alias from a prompt, preventing further loads via that alias name. Both functions delegate to the underlying mlflow.tracking._model_registry.fluent module, which interacts with the MLflow tracking store.
Together, these two functions provide the complete lifecycle for alias management: creation, reassignment (by calling set_prompt_alias with a new version), and deletion.
Usage
Use set_prompt_alias() after registering one or more prompt versions, when you are ready to designate a specific version for a deployment stage. Use delete_prompt_alias() when retiring an alias that is no longer needed.
Code Reference
Source Location
- Repository: mlflow
- File:
mlflow/genai/prompts/__init__.py - Lines: L221-250 (set_prompt_alias), L253-263 (delete_prompt_alias)
Signature
def set_prompt_alias(name: str, alias: str, version: int) -> None:
...
def delete_prompt_alias(name: str, alias: str) -> None:
...
Import
import mlflow.genai
# Then call:
# mlflow.genai.set_prompt_alias(...)
# mlflow.genai.delete_prompt_alias(...)
I/O Contract
Inputs (set_prompt_alias)
| Name | Type | Required | Description |
|---|---|---|---|
| name | str | Yes | The name of the registered prompt. |
| alias | str | Yes | The alias to assign (e.g., "production", "staging"). If the alias already exists, it is reassigned to the specified version. |
| version | int | Yes | The version number of the prompt to which the alias should point. |
Inputs (delete_prompt_alias)
| Name | Type | Required | Description |
|---|---|---|---|
| name | str | Yes | The name of the registered prompt. |
| alias | str | Yes | The alias to delete. |
Outputs
| Name | Type | Description |
|---|---|---|
| set_prompt_alias return | None | The function returns nothing. The alias is set as a side effect in the registry. |
| delete_prompt_alias return | None | The function returns nothing. The alias is removed as a side effect in the registry. |
Usage Examples
Basic Usage: Set and Load by Alias
import mlflow.genai
# Register two versions of a prompt
mlflow.genai.register_prompt(
name="qa_prompt",
template="Answer the following question: {{question}}",
)
mlflow.genai.register_prompt(
name="qa_prompt",
template="Please answer concisely: {{question}}",
commit_message="Make prompt more concise",
)
# Set the "production" alias to version 1
mlflow.genai.set_prompt_alias(name="qa_prompt", alias="production", version=1)
# Load the prompt by alias
prompt = mlflow.genai.load_prompt("prompts:/qa_prompt@production")
print(prompt.version) # 1
print(prompt.template) # "Answer the following question: {{question}}"
Promote a New Version to Production
import mlflow.genai
# Reassign the "production" alias to version 2
mlflow.genai.set_prompt_alias(name="qa_prompt", alias="production", version=2)
# All consumers loading by alias now get version 2 automatically
prompt = mlflow.genai.load_prompt("prompts:/qa_prompt@production")
print(prompt.version) # 2
print(prompt.template) # "Please answer concisely: {{question}}"
Delete an Alias
import mlflow.genai
# Remove the "staging" alias when it is no longer needed
mlflow.genai.delete_prompt_alias(name="qa_prompt", alias="staging")