Back to Prefect

How to customize a workflow's metadata

docs/v3/how-to-guides/workflows/custom-metadata.mdx

3.7.01.7 KB
Original Source

Customize a workflow's name

Give your workflow a name with the name parameter:

python
from prefect import flow


@flow(name="My Flow")
def my_workflow() -> str:
    return "Hello, world!"

If you don't provide a name, Prefect uses the flow function name.

Customize a workflow's description

Give your workflow a description with the description parameter:

python
from prefect import flow


@flow(name="My Flow", description="My flow with a name and description")
def my_workflow() -> str:
    return "Hello, world!"

If no description is provided, a flow function's docstring is used as the description.

Customize run names

Give a custom name to each flow run for a flow with the flow_run_name parameter:

python
import datetime
from prefect import flow


@flow(flow_run_name="hello-{name}-on-{date:%A}")
def my_workflow(name: str, date: datetime.datetime):
    return f"I said hello to {name} on {date:%A}!"

Inputs to the flow function are available as variables in the flow_run_name template string.

You can also provide a flow_run_name as a function that returns a string:

python
import datetime
from prefect import flow


def generate_flow_run_name():
    date = datetime.datetime.now(datetime.timezone.utc)
    return f"{date:%A}-is-a-nice-day"


@flow(flow_run_name=generate_flow_run_name)
def my_workflow(name: str):
    return f"Hello, {name}!"
<Info> **Custom flow run names are applied at runtime**

When a flow run is created via a schedule or the API, the flow_run_name defined on the flow is not immediately applied. The name is set just before the flow enters the Running state, so the Running event and all subsequent events reflect the custom name. </Info>