Customize notifications in prefect orion notifications tab

Is there a way to change the function that creates the notification message created automatically when notification is set up on the Orion server?

Is there a way to use custom NotificationBlock to notify in the prefect Orion server? Do we simply need to create and register such NotificationBlock to make it available in the notification tab of the server?

1 Like

You can implement custom notification blocks and register those. Alternatively, you can send customized alerts from your code, e.g.:

from prefect import flow, task
from prefect.blocks.notifications import SlackWebhook

def send_alert():
    slack_webhook_block = SlackWebhook.load("slacknotificationblocktest") 
    slack_webhook_block.notify("Hello from Prefect!") 

def notification_flow():

I was able to register a custom notification block class, and I can create instances on the UI.
It is working fine when I create a test block on the UI and load it to notify by hand.

However, when adding a notification via the UI with this new custom type (policy all tags and all states), it fails to notify with the following error:

Error sending notification for policy 85df5553-6aab-47eb-800a-40dd407c522b on flow run 9703078b-257c-4455-a187-90adf0b3412a
Traceback (most recent call last):
  File "/home/nduminy/.pyenv/versions/3.9.7/envs/youtube-v2-test/lib/python3.9/site-packages/prefect/orion/services/", line 88, in send_flow_run_notification
    block = Block._from_block_document(
  File "/home/nduminy/.pyenv/versions/3.9.7/envs/youtube-v2-test/lib/python3.9/site-packages/prefect/blocks/", line 401, in _from_block_document
    else cls.get_block_class_from_schema(block_document.block_schema)
  File "/home/nduminy/.pyenv/versions/3.9.7/envs/youtube-v2-test/lib/python3.9/site-packages/prefect/blocks/", line 432, in get_block_class_from_schema
    return lookup_type(cls, block_schema_to_key(schema))
  File "/home/nduminy/.pyenv/versions/3.9.7/envs/youtube-v2-test/lib/python3.9/site-packages/prefect/utilities/", line 186, in lookup_type
    raise KeyError(
KeyError: "No class found for dispatch key 'mattermost-webhook' in registry for type 'Block'."

The class for the custom block is exactly the same as the SlackWebhook one.

1 Like

Let me ask the team, someone was recently working on the same to add Teams webhook