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
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/prefectgives 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
10 seconds by default, and you can change it with the block's timeout field Retries not documented so plan for a lost notification and for a repeat After a failure an error for any response outside 2xx, including a redirect, or a timeout. Nothing is sent to your service Duplicates not documented and nothing identifies a delivery, so put your own key in the message Known failure modes
From Hookdeck's Prefect guide →-
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 → -
The request doesn't say what fired it
Prefect sends no event name, flow run ID or state unless your template includes them, and
Design requests you can route →{{body}}is free text by default. Add{{ flow_run.id }},{{ flow_run.state.name }}and{{ automation.name }}to the automation's message. -
A flow run variable in the block is rejected
A Custom Webhook block accepts only
Use the right template →{{subject}},{{body}},{{name}}and keys in itssecrets, 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. -
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
- Put the identifiers in the automation's message.
The block only accepts
subject,body,nameand its own secrets as placeholders, so{{ flow_run.id }}and similar variables belong in the action's subject or body. - Deduplicate on your own key.
Prefect adds no delivery ID. Include
{{ automation.name }}and{{ event.id }}in the message, and skip a pair you've already processed. - Respond inside the block's timeout. The block allows 10 seconds by default. Store the request, respond and do the work from a queue.
- Plan for a lost notification. Prefect's docs don't say a failed notification is sent again, so reconcile against the Prefect API rather than relying on every request arriving.
- Keep the secret in
secrets. Reference it as a placeholder in the header, so it stays out of the block's plain configuration and rotating it is one change.
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.