Solomon Negusse
10/17/2025, 10:09 AMMarvin
10/17/2025, 10:09 AMMarvin
10/17/2025, 10:12 AMblocks and attachments (and attachments may contain their own blocks). Using color with values like `good`/`danger` is valid for attachments.
- Your Block Kit structure (divider, header, section) looks fine.
What needs fixing:
- The quotes in your snippet are “smart quotes” (curly). Slack expects valid JSON with straight quotes. Replace all “ ” and ‘ ’ with " and '.
Potential issue depending on how you send it from Prefect:
- If you’re using Prefect’s built-in Slack Notification block (SlackWebhook), it sends simple messages (subject/body), not arbitrary JSON payloads. To post raw Block Kit JSON, use a Custom Webhook pointing at a Slack Incoming Webhook, or the prefect-slack integration.
- The Jinja variables you’re using (flow_run, flow) will only render if the context is provided by the sender. In Prefect 3.x, Automations for flow-run events generally provide flow_run, flow, and deployment in the template context; a standalone block call may not. Please confirm how you’re sending this (Automation vs. a block in code) so I can tailor the exact template.
Here’s your payload corrected to valid JSON with straight quotes (structure-wise valid for Slack Incoming Webhooks), keeping your Jinja logic intact:
{
"blocks": [
{
"type": "divider"
}
],
"attachments": [
{
"color": "{% if flow_run.state.name == 'Completed' %}good{% else %}danger{% endif %}",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "{{ flow.name|upper }} - {{ flow_run.state.name|upper }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "{{ flow_run.state.message }}"
}
}
]
}
]
}
Follow-ups to make sure this works for you:
- How are you sending this from Prefect? (Automation action, Custom Webhook block to an Incoming Webhook URL, or the Slack Notification block?)
- If it’s an Automation, which event are you triggering on? I can confirm the exact context variables available.
References:
- Slack Incoming Webhooks and message payloads: Slack webhooks
- Block Kit reference: Block types and Attachments
- Prefect 3.x notification blocks: Prefect notification blocks
- Prefect Slack integration (for richer Slack interactions): prefect-slack integrationSolomon Negusse
10/17/2025, 10:16 AMMarvin
10/17/2025, 10:16 AMMarvin
10/17/2025, 10:19 AMflow_run, flow, and deployment when the trigger is a flow-run event, so your {{ flow.* }} and {{ flow_run.* }} references should render.
- This is the recommended path for Block Kit.
2) If you use the “Send Slack notification” action
- It only supports a text message (no Block Kit/attachments). You’d need to convert to plain text.
Here’s your payload corrected to valid JSON with straight quotes (works for a webhook action):
{
"blocks": [
{
"type": "divider"
}
],
"attachments": [
{
"color": "{% if flow_run.state.name == 'Completed' %}good{% else %}danger{% endif %}",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "{{ flow.name|upper }} - {{ flow_run.state.name|upper }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "{{ flow_run.state.message }}"
}
}
]
}
]
}
Quick check:
- Variables available for flow-run triggers typically include flow_run (name, parameters, state, tags, id, etc.), flow, and deployment.
- Mixing top-level blocks with attachments containing their own blocks is allowed by Slack.
Can you confirm which automation action you’re using: “Send Slack notification” or a webhook-based action (e.g., “Call a webhook” / Custom Webhook)? I can give you exact UI steps for that path.
References:
- Prefect Automations overview: Automations in Prefect 3
- Notification blocks: Notification blocks API
- Slack Incoming Webhooks: Slack webhooks
- Block Kit reference: Block Kit and AttachmentsSolomon Negusse
10/17/2025, 11:03 AMMarvin
10/17/2025, 11:03 AMMarvin
10/17/2025, 11:04 AMflow_run, flow, and deployment are available in the template context. Minor improvements:
- Include a top-level text as a fallback so mobile/notifications show something even if blocks don’t render.
- Default the state message to empty to avoid “null” if there’s no message.
Drop-in payload you can use:
{
"text": "{{ flow.name }} - {{ flow_run.state.name }}",
"blocks": [
{
"type": "divider"
}
],
"attachments": [
{
"color": "{% if flow_run.state.name == 'Completed' %}good{% else %}danger{% endif %}",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "{{ flow.name|upper }} - {{ flow_run.state.name|upper }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "{{ flow_run.state.message | default('') }}"
}
}
]
}
]
}
Notes:
- Mixing top-level blocks and attachments with their own blocks is supported by Slack.
- Make sure all quotes are straight quotes.
Docs for reference:
- Prefect Automations: Automations in Prefect 3
- Slack Incoming Webhooks: Slack webhooks
- Block Kit reference: Block types and Attachments