Akash N
07/29/2026, 11:53 AMMarvin
07/29/2026, 11:53 AMMarvin
07/29/2026, 11:54 AMname argument on `@task`:
python
from prefect import task
@task(name="My custom task")
def do_work():
return 1
If you don’t set it, Prefect uses the Python function name.
Dynamic task run name
If you want each execution of the task to have a custom name, use `task_run_name`:
python
from prefect import flow, task
@task(name="process-order", task_run_name="process-order-{order_id}")
def process(order_id: int):
return order_id
@flow
def my_flow():
process(123)
That gives the task definition the name process-order, and the run a name like process-order-123.
You can also use a callable for task_run_name if you need more control.
So in short:
- name= → names the task itself
- task_run_name= → names each task run
If you want, I can show the exact pattern for your use case.Akash N
07/29/2026, 1:56 PM@task
def execute_api(config):
api.get_api_data(config)Marvin
07/29/2026, 1:57 PMMarvin
07/29/2026, 1:58 PMtask_run_name and reference fields from config.
For your example:
python
from prefect import task
@task(task_run_name="execute-api-{config[orderid]}")
def execute_api(config):
api.get_api_data(config)
If config is:
python
{"orderid": 123}
then the task run name will be:
python
execute-api-123
A slightly safer option is to use a callable, especially if orderid might be missing:
python
from prefect import task
def make_task_name(parameters):
config = parameters.get("config", {})
order_id = config.get("orderid", "unknown")
return f"execute-api-{order_id}"
@task(task_run_name=make_task_name)
def execute_api(config):
api.get_api_data(config)
That avoids errors if config["orderid"] is absent.
So your task definition can stay:
python
@task(name="execute_api")
or just @task, but for per-order names, use task_run_name.
If you want, I can also show how this appears when the task is called from a flow.