<@ULVA73B9P> can you generate a yaml for adding an...
# ask-marvin
c
@Marvin can you generate a yaml for adding an automation with action type send-notification triggered when "flw-A" enters failed state
m
thought for 304.9 seconds
Here’s a minimal Prefect 3.x automation YAML that sends a notification when the flow named “flw-A” enters a Failed state. Replace the
block_document_id
with your notification block’s UUID.
Copy code
name: "Notify on flw-A failure"
description: "Send a notification when flow 'flw-A' fails"
enabled: true

trigger:
  type: "event"
  posture: "Reactive"
  expect:
    - "prefect.flow-run.Failed"
  match: {}
  match_related:
    prefect.resource.role: "flow"
    prefect.resource.name: "flw-A"
  threshold: 1

actions:
  - type: "send-notification"
    block_document_id: "REPLACE_WITH_BLOCK_UUID"
    subject: "Flow failed: {{ flow.name }} (run {{ flow_run.name }})"
    body: |
      Flow '{{ flow.name }}' run {{ flow_run.name }} has failed.
      State: {{ flow_run.state.name }}
      Message: {{ flow_run.state.message }}
      View: {{ flow_run|ui_url }}
Apply it with:
Copy code
prefect automation create -f automation.yaml
Helpful docs: - Automations concepts - Creating automations
c
I dont want to use a block and pass in an email address
can you regenerate the yaml
@Marvin can you regenerate the automation yaml which takes in an email address rather than using a block
m
thought for 179.3 seconds
Short answer: In Prefect 3.x, the send-notification action cannot send directly to an email address. It must reference a pre-configured notification block (e.g., SendGrid Email). There’s no email_addresses field on the action. If you need to pass an email address in YAML, the closest supported pattern is to use a call-webhook action that posts to your email provider’s HTTP API. You’ll still need a one-time Webhook block (to hold the URL, method, and headers), but the recipient can live in the YAML payload. Example (triggers when flow “flw-A” fails):
Copy code
name: "Email on flw-A failure via webhook"
description: "Send an email when flow 'flw-A' fails using a generic email API"
enabled: true

trigger:
  type: "event"
  posture: "Reactive"
  expect:
    - "prefect.flow-run.Failed"
  match: {}
  match_related:
    prefect.resource.role: "flow"
    prefect.resource.name: "flw-A"
  threshold: 1

actions:
  - type: "call-webhook"
    block_document_id: "REPLACE_WITH_WEBHOOK_BLOCK_UUID"
    payload: |
      {
        "to": "<mailto:alerts@example.com|alerts@example.com>",
        "from": "<mailto:prefect@example.com|prefect@example.com>",
        "subject": "Flow failed: {{ flow.name }} (run {{ flow_run.name }})",
        "text": "Flow '{{ flow.name }}' run {{ flow_run.name }} has failed.\nState: {{ flow_run.state.name }}\nMessage: {{ flow_run.state.message }}\nView: {{ flow_run|ui_url }}"
      }
How to apply: - Create a Webhook block pointing at your email API endpoint (e.g., Mailgun/SendGrid HTTP API) with necessary headers and method. Then copy its block_document_id. - Apply the automation:
Copy code
prefect automation create -f automation.yaml
If you’re open to using a notification block (the simplest path for email), create a “SendGrid Email” notification block with your recipients and use send-notification instead. Docs: - Automations concepts - Custom notifications (webhooks, templating) If you tell me which email provider you use (SendGrid, Mailgun, SES, etc.), I can provide the exact Webhook block config and payload format.
c
@Marvin I dont want to call a webhook. Can I pass in an email address to the send-notification block?
m
thought for 37.1 seconds
c
I want to create an action of type "send-notifications"
m
Short answer: No. The send-notification action doesn’t accept raw email addresses. It only takes: - type: "send-notification" - block_document_id: <UUID of a notification block> - subject - body To send email, put the recipients on a notification block (e.g., a SendGrid Email block) and reference that block from the automation. Typical setup: 1) Create a SendGrid Email block (UI: Blocks -> Create -> SendGrid Email). Set: - sender_email - to_emails (your recipients) - api_key 2) Get the block’s ID:
Copy code
prefect block ls
prefect block inspect sendgrid-email/<your-block-name>
3) Use it in your automation YAML:
Copy code
name: "Email on flw-A failure"
description: "Send an email when flow 'flw-A' fails"
enabled: true

trigger:
  type: "event"
  posture: "Reactive"
  expect:
    - "prefect.flow-run.Failed"
  match: {}
  match_related:
    prefect.resource.role: "flow"
    prefect.resource.name: "flw-A"
  threshold: 1

actions:
  - type: "send-notification"
    block_document_id: "REPLACE_WITH_SENDGRID_BLOCK_UUID"
    subject: "Flow failed: {{ flow.name }} (run {{ flow_run.name }})"
    body: |
      Flow '{{ flow.name }}' run {{ flow_run.name }} has failed.
      State: {{ flow_run.state.name }}
      Message: {{ flow_run.state.message }}
      View: {{ flow_run|ui_url }}
Apply it:
Copy code
prefect automation create -f automation.yaml
Docs: - Automations concepts - Custom notifications
c
@Marvin I want to use an action type: "send-notification" and pass in an email address without using a block. can you generate the automation yaml
m
thought for 24.8 seconds
I can’t generate that YAML because it isn’t supported. In Prefect 3.x, the send-notification action does not accept raw email addresses. Its schema requires a notification block and only supports: - type - block_document_id - subject - body If you want email, you’ll need to create a notification block (e.g., a SendGrid Email block) with your recipients, then reference it. Here’s the correct automation YAML targeting flow “flw-A”:
Copy code
name: "Email on flw-A failure"
description: "Send an email when flow 'flw-A' fails"
enabled: true

trigger:
  type: "event"
  posture: "Reactive"
  expect:
    - "prefect.flow-run.Failed"
  match: {}
  match_related:
    prefect.resource.role: "flow"
    prefect.resource.name: "flw-A"
  threshold: 1

actions:
  - type: "send-notification"
    block_document_id: "REPLACE_WITH_SENDGRID_BLOCK_UUID"
    subject: "Flow failed: {{ flow.name }} (run {{ flow_run.name }})"
    body: |
      Flow '{{ flow.name }}' run {{ flow_run.name }} has failed.
      State: {{ flow_run.state.name }}
      Message: {{ flow_run.state.message }}
      View: {{ flow_run|ui_url }}
To set up the block: - Create a SendGrid Email block (set sender_email, to_emails, api_key) in the UI, then copy its ID. - Apply the automation:
Copy code
prefect automation create -f automation.yaml
References: - Automations concepts - Creating automations - Custom notifications If avoiding blocks entirely is a hard requirement, Prefect’s automations can’t send email directly. The only other automation-based route is a call-webhook action to an email API (which you said you don’t want). If you’d like, I can help you set up the SendGrid block quickly or suggest an in-flow notification pattern instead.