Kyle McChesney
05/26/2026, 3:49 PM@task(task_run_name='refresh-{display_name}') but display name is human readable text (spaces, capitals, etc). I want to convert it to kebabMarvin
05/26/2026, 3:50 PMMarvin
05/26/2026, 3:51 PMtask_run_name does not support Jinja filters/templating in Prefect 3.x.
A string like:
python
@task(task_run_name="refresh-{display_name}")
uses Python .format(...)-style substitution, not Jinja, so you can't do things like |lower, replace, etc.
Best option: use a callable for task_run_name and transform the parameter there.
Example:
python
from prefect import task
def to_kebab(s: str) -> str:
return s.strip().lower().replace(" ", "-").replace("_", "-")
def task_name(parameters: dict) -> str:
return f"refresh-{to_kebab(parameters['display_name'])}"
@task(task_run_name=task_name)
def refresh(display_name: str):
pass
If you want a one-liner:
python
from prefect import task
@task(
task_run_name=lambda parameters: (
f"refresh-{parameters['display_name'].strip().lower().replace(' ', '-').replace('_', '-')}"
)
)
def refresh(display_name: str):
pass
A few notes:
- String templates support basic field access like {display_name}
- They can also handle some normal Python format spec behavior
- They do not support filters, arbitrary expressions, or case conversion
So for kebab-case, a callable is the right approach.
Relevant docs/source:
- Prefect docs
- Prefect task naming is implemented with Python string formatting / callable support in Prefect 3.x source: Prefect GitHub
If you want, I can also give you a more robust to_kebab() helper that handles multiple spaces, punctuation, and unicode more cleanly.