chase albright
10/10/2025, 3:44 PMMarvin
10/10/2025, 3:46 PMMarvin
10/10/2025, 3:48 PMprefect.blocks.notifications.SlackWebhook
- Microsoft Teams: prefect.blocks.notifications.MicrosoftTeamsWebhook
- Also available: CustomWebhookNotificationBlock
, AppriseNotificationBlock
, PagerDuty, Twilio SMS, Opsgenie, Discord, Mattermost, Sendgrid
- Cloud-only: Automations that alert on flow/task state changes without code.
Docs:
- Slack integration overview
- Prefect Server (OSS) concept overview
Example: Slack alert on failure (OSS-safe: no Cloud features required)
from prefect import flow
from prefect.blocks.notifications import SlackWebhook
# Option A: Load a saved block (recommended for prod)
# slack = SlackWebhook.load("my-slack")
# Option B: Create inline (good for testing)
slack = SlackWebhook(url="<https://hooks.slack.com/services/XXX/YYY/ZZZ>")
@flow
def my_flow():
try:
# your logic here
1 / 0
except Exception as exc:
slack.notify(f"❌ Flow failed: {exc}")
raise
if __name__ == "__main__":
my_flow()
Example: Microsoft Teams alert on completion/failure
from prefect import flow
from prefect.blocks.notifications import MicrosoftTeamsWebhook
teams = MicrosoftTeamsWebhook(url="<https://outlook.office.com/webhook/XXX>")
@flow
def my_flow():
try:
# work
pass
except Exception as exc:
teams.notify(f"❌ Flow failed: {exc}")
raise
else:
teams.notify("✅ Flow completed successfully")
if __name__ == "__main__":
my_flow()
Tips:
- For richer formatting, assemble your own message text; the blocks accept a simple string body.
- You can also wire notifications into your own error-handling strategy (e.g., at task boundaries) or implement a small monitoring flow that queries late/failed runs and posts to Slack/Teams on a schedule.
- If you prefer no-code/low-code alert rules across all runs, that’s what Prefect Cloud Automations provide.
If you want, tell me whether you’re on Slack or Teams, and I can share a minimal setup (including how to save and reuse a secure block) tailored to your environment.