<@ULVA73B9P> I'm trying to configure an automation...
# ask-marvin
d
@Marvin I'm trying to configure an automation to send me a message when a flow_run fails. My message is: "Flow {{ flow-run.name }} is in state {{ flow-run.state }} for deployment {{ deployment.name }}. [https://app.prefect.cloud/account/****/workspace/****/runs/flow-run/{{ flow-run.id }}]" My automation is failing with :
Copy code
"{\n  \"error\": {\n    \"code\": 400,\n    \"message\": \"Invalid JSON payload received. Unexpected token.\\nFailed to render tem\\n^\",\n    \"status\": \"INVALID_ARGUMENT\"\n  }\n}\n"
I believe is linked to one of the following params doesn't exist: • flow-run.name • flow-run.state • deployment.name • flow-run.id How can I fix this
m
thought for 265.3 seconds
You’re right — this is a templating issue. In Prefect 3.x automations, variables use underscores (not hyphens) and
flow_run.state
is an object, so you’ll typically want
.name
or
.type
. Also, your
{{> flow-run.id }}
has an extra
>
and the hyphenated variable name will break rendering. Use these instead: -
flow_run.name
-
flow_run.state.name
(or
flow_run.state.type
) -
deployment.name
-
flow_run.id
Even better, you can avoid hardcoding the UI path by using the built-in
ui_url
filter. If you’re sending a Slack notification (Send Notification action), a good template is:
Copy code
Flow {{ flow_run.name }} is in state {{ flow_run.state.name }} for deployment {{ deployment.name|default('N/A') }}. <{{ flow_run|ui_url }}|Open run>
If you’re calling a webhook that expects JSON, make sure your payload renders valid JSON. For example:
Copy code
{
  "text": "Flow {{ flow_run.name }} is in state {{ flow_run.state.name }} for deployment {{ deployment.name|default('N/A') }}. {{ flow_run|ui_url }}"
}
Notes: - Don’t use `flow-run.*`; use
flow_run.*
. - Don’t reference
flow_run.state
directly in strings; pick a field like
.name
or
.type
. - Avoid square brackets around Slack links. Use
<url|text>
format. -
deployment.name
can be missing for ad‑hoc runs, so
|default('N/A')
prevents nulls. If you tell me whether you’re using “Send notification” or “Call webhook” and which destination (Slack, Teams, etc.), I can tailor the exact message/payload for you.