Theom
03/16/2026, 9:00 AMMarvin
03/16/2026, 9:00 AMMarvin
03/16/2026, 9:07 AMflow_run in Prefect 3.x automations, but you need to explicitly serialize it. Jinja templates always render to strings, so to get a “dictionary” on the receiving side you’ll either pass a JSON string or wrap it so Prefect parses it back into a dict.
What works
- Full JSON string of the flow run:
{{ flow_run.model_dump_json() }}
- If you need a real Python dict (e.g., as a parameter to RunDeployment), wrap the Jinja output in a JSON handler so it’s parsed:
{
"upstream_flow_run": {
"__prefect_kind": "json",
"value": {
"__prefect_kind": "jinja",
"template": "{{ flow_run.model_dump_json() }}"
}
}
}
Notes
- {{ flow_run }} will just be a string representation, not useful JSON.
- {{ flow_run | tojson }} will not work on its own—the flow_run is a Pydantic model; use model_dump_json() or model_dump(mode='json') | tojson instead.
- If the field only accepts strings (e.g., webhook payload or notification body), use the JSON string form (model_dump_json()).
- If you only need a subset, you can build and parse just what you want:
{
"flow_run_min": {
"__prefect_kind": "json",
"value": {
"__prefect_kind": "jinja",
"template": "{{ {'id': flow_run.id, 'name': flow_run.name, 'state': flow_run.state.type.value, 'parameters': flow_run.parameters} | tojson }}"
}
}
}
If you can share which action you’re configuring (RunDeployment, CallWebhook, SendNotification, etc.), I can tailor the exact snippet.
Helpful docs:
- Templating with Jinja
- Access parameters in templates