<@ULVA73B9P> I have an automation that takes as ar...
# ask-marvin
t
@Marvin I have an automation that takes as arguments things coming from another flow like {{ flow_run.id }} or {{ flow_run.parameters }}. Is it possible to provide the {{ flow_run }} as a whole and get the flow_run e.g. in dictionary form?
m
thought for 420.0 seconds
Short answer: yes—you can reference the entire
flow_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:
Copy code
{{ 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:
Copy code
{
  "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:
Copy code
{
  "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