<@ULVA73B9P> how can i pass the payload of an even...
# ask-marvin
p
@Marvin how can i pass the payload of an event (which is a nested dict) to a deployment when starting the deployment via an automation? The flow looks like this:
Copy code
@flow(name="Support Bot", persist_result=False)
def support_bot(event_data: dict): ...
m
thought for 166.2 seconds
You can pass the event payload directly to your deployment using an Automation “Run deployment” action with a Jinja placeholder. In Prefect 3.x, the Parameters field supports placeholders that can inject the raw event dict (including nested data) into your flow’s parameters. For your flow
Copy code
@flow(name="Support Bot", persist_result=False)
def support_bot(event_data: dict):
    ...
Set the Automation action’s Parameters JSON like this:
Copy code
{
  "event_data": {
    "__prefect_kind": "jinja",
    "template": "{{ event.payload }}"
  }
}
Notes and tips: - To pass the entire event object instead of just the payload:
Copy code
{
  "event_data": {
    "__prefect_kind": "jinja",
    "template": "{{ event }}"
  }
}
- Access nested keys with dot notation or brackets:
Copy code
{
  "ticket_id": {
    "__prefect_kind": "jinja",
    "template": "{{ event.payload.ticket.id }}"
  },
  "weird_key": {
    "__prefect_kind": "jinja",
    "template": "{{ event.payload['nested']['weird-key'] }}"
  }
}
- Don’t wrap the template in quotes—use the placeholder object as shown so Prefect can inject the raw dict. - If your event might not include a payload, you can provide a safe default:
Copy code
{
  "event_data": {
    "__prefect_kind": "jinja",
    "template": "{{ event.payload | default({}) }}"
  }
}
Docs for more detail: - Use templates in Automations - Chain deployments with events If you can share a sample event payload, I can tailor the exact Parameters JSON for your case.
p
@Marvin But i get an error:
Copy code
"Error creating flow run: Validation failed for field 'event_data'. Failure reason: \"{...}}\" is not of type 'object'". This just passes the dict as string instead of object
m
thought for 179.5 seconds
You’re running into a known behavior: in some Prefect 3.x versions the Automation “Run deployment” action renders Jinja results as strings. So
{{ event.payload }}
becomes a JSON-looking string, which then fails validation for a
dict
-typed parameter. Tracked here: Automation Action passes non-string types as strings. Workarounds you can use right now: 1) Wrap Jinja with a JSON placeholder to force decoding into an object This makes Prefect render the payload with Jinja, then parse it as JSON, so the parameter is a real dict.
Copy code
{
  "event_data": {
    "__prefect_kind": "json",
    "json": {
      "__prefect_kind": "jinja",
      "template": "{{ event.payload | tojson }}"
    }
  }
}
2) If only certain nested fields are needed, build the object explicitly and use JSON wrapping per field where needed
Copy code
{
  "event_data": {
    "ticket_id": {
      "__prefect_kind": "jinja",
      "template": "{{ event.payload.ticket.id }}"
    },
    "metadata": {
      "__prefect_kind": "json",
      "json": {
        "__prefect_kind": "jinja",
        "template": "{{ event.payload.metadata | tojson }}"
      }
    }
  }
}
3) As a last resort, loosen the parameter type and parse inside the flow If 1) isn’t available in your workspace, accept a string-or-dict and coerce:
Copy code
from typing import Any
import json
from prefect import flow

@flow(name="Support Bot", persist_result=False)
def support_bot(event_data: Any):
    if isinstance(event_data, str):
        event_data = json.loads(event_data)
    ...
References: - Use templates in Automations - Chain deployments with events If you can share your Prefect version (Cloud/Server and Prefect package), I can confirm whether the JSON-wrapper approach should work in your environment and tailor the exact Parameters JSON to your payload.