Use the prefect.runtime module to access runtime information from within a workflow.

from prefect import flow
from prefect.runtime import flow_run


@flow
def moody_workflow(name: str):
    return f"I wish my parents had named me {name} instead of {flow_run.name}."

The value of flow_run.name will change between workflow runs to match the name of the flow run.

Attributes of prefect.runtime are None if a value is not available

Attributes of prefect.runtime will never error when accessed. If a value is not available, the attribute will be None.

from prefect.runtime import flow_run

assert flow_run.name is None

See the prefect.runtime module reference for all available attributes.