Prefect webhooks

Prefect webhooks are HTTP requests that a Custom Webhook notification block makes to your endpoint when an automation's notification action fires, or when your code calls notify().

These pages cover requests a Prefect automation sends through a Custom Webhook notification block. To send events into Prefect, see Prefect Cloud webhooks. The separate Call a webhook action uses a different block and isn't covered here.

How Prefect webhooks work

An automation pushes to your service when its trigger matches, so you don't have to poll Prefect for run states. Triggers cover flow run state changes, work pool, work queue and deployment status, metric thresholds and custom events, and they can also fire when an expected event doesn't happen. The **Send a notification** action names a saved block and supplies a subject and body written in Jinja, which Prefect renders before the block sends the request.

You write the request. The block sets the method (POST by default), URL, query params, headers, cookies and either json_data or form_data, and substitutes {{subject}}, {{body}}, {{name}} and any key in its secrets. Prefect adds only User-Agent: Prefect Notifications, so there are no event names, no event header and no version to read. Names such as prefect.flow-run.Failed are what triggers match on, and they aren't sent. To tell deliveries apart, put {{ automation.name }} or {{ flow_run.state.name }} in the automation's message, or give each automation its own block with a fixed field in json_data.

Key facts

Signature header
None (unsigned)
How events are identified
Not sent: route on a field you add to the template
Body format
SENDER-DEFINED
Other headers
user-agent
Agent skill
npx skills add hookdeck/webhook-skills --skill prefect-webhooks

Verify Prefect webhooks →

Setting up Prefect webhooks

  • Create a **Custom Webhook** block with your endpoint as the **Webhook URL** and your body under **JSON Data**. Add a secret under **Custom Secret Values**, then send it from **Headers**, for example as X-Prefect-Secret: {{webhook_secret}}.
  • Add a **Send a notification** action to an automation, choose the block and write the subject and body. Without a subject, Prefect uses Prefect automated notification.
  • To test without an automation, call CustomWebhookNotificationBlock.load("my-block").notify("test"), which raises an error on a failed send. hookdeck listen 3000 prefect --path /webhooks/prefect gives you a public URL that forwards to your machine.
  • Prefect documents no way to resend a notification, so a resend means firing the automation again. Routing through Hookdeck adds replay. On a Prefect source, enter the header name and the secret's real value, not the placeholder.

Delivery behaviour

  1. A notification can be lost while your endpoint is down

    The block treats any response outside 2xx as an error, and Prefect's docs don't say a failed notification is sent again. Reconcile against the Prefect API, for example by querying recent failed flow runs, so a missed notification is caught.

    Plan for failed sends →
  2. The request doesn't say what fired it

    Prefect sends no event name, flow run ID or state unless your template includes them, and {{body}} is free text by default. Add {{ flow_run.id }}, {{ flow_run.state.name }} and {{ automation.name }} to the automation's message.

    Design requests you can route →
  3. A flow run variable in the block is rejected

    A Custom Webhook block accepts only {{subject}}, {{body}}, {{name}} and keys in its secrets, and raises an error on anything else when it's created. Put Jinja variables such as {{ flow_run.id }} in the automation's subject or body instead.

    Use the right template →
  4. A slow handler counts as a failed notification

    The block allows 10 seconds by default, and a timeout is an error even if your handler finishes the work afterwards. Store the request, respond and do the work from a queue.

    Respond in time →

Prefect webhook best practices

In this hub

MCP events → How an agent subscribes to Prefect events as MCP events.
Verify signatures → Signature facts, verification code and common failures.
Production guide → Production problems, such as timeouts and retries, and how to handle them.
Agent skill → Install the webhook skill in your coding agent. npx skills add hookdeck/webhook-skills --skill prefect-webhooks

Keep an outage on your side from losing Prefect alerts.

Event Gateway checks the secret header, stores each notification as it arrives and delivers it to your service with retries you control, and you can replay any of them after a fix.

Not affiliated with Prefect. Facts are compiled from public sources and linked inline.