Madushan Pathirana
06/30/2026, 2:30 PMMarvin
06/30/2026, 2:30 PMMarvin
06/30/2026, 2:31 PMflow_run_name string templates only support simple parameter formatting like {txn_path} — not Python expressions like slicing.
So this:
python
@flow(
name="NETS-Extraction",
flow_run_name="txn:{txn_path[-16:-8]}-prf:{profiles_path[-16:-8]}",
log_prints=True,
)
def run(txn_path: str, profiles_path: str):
...
fails because Prefect treats flow_run_name as:
python
flow_run_name.format(**parameters)
and Python str.format() cannot evaluate [-16:-8] inside {...}.
That’s why you get:
python
TypeError: string indices must be integers, not 'str'
What to do instead
Option 1: use a callable for flow_run_name
This is the cleanest fix for your case.
python
from prefect import flow
from prefect.context import FlowRunContext
def make_flow_run_name():
ctx = FlowRunContext.get()
params = ctx.parameters if ctx else {}
txn_path = params.get("txn_path", "")
profiles_path = params.get("profiles_path", "")
txn_part = txn_path[-16:-8] if len(txn_path) >= 16 else txn_path
profiles_part = profiles_path[-16:-8] if len(profiles_path) >= 16 else profiles_path
return f"txn:{txn_part}-prf:{profiles_part}"
@flow(
name="NETS-Extraction",
flow_run_name=make_flow_run_name,
log_prints=True,
)
def run(txn_path: str, profiles_path: str):
print("running")
Option 2: pass precomputed parameters and use simple placeholders
python
from prefect import flow
@flow(
name="NETS-Extraction",
flow_run_name="txn:{txn_part}-prf:{profiles_part}",
log_prints=True,
)
def run(txn_path: str, profiles_path: str, txn_part: str, profiles_part: str):
print("running")
run(
txn_path="some/long/path/20240101_file.csv",
profiles_path="some/other/path/20240102_file.csv",
txn_part="20240101",
profiles_part="20240102",
)
Important detail
For flows, a callable flow_run_name is called with no arguments, so this will not work:
python
def make_flow_run_name(parameters):
...
Instead, use FlowRunContext.get() as shown above.
In short:
- {txn_path} works
- {txn_path[-16:-8]} does not work
- use a callable if you need slicing/logic
Relevant source-backed behavior:
- Prefect 3.x resolves string flow_run_name via str.format(**parameters)
- callable flow_run_name is supported for flows, but called without parameters
If you want, I can also rewrite your exact decorator/code into a drop-in fixed version.