<@ULVA73B9P> does the open source version of prefe...
# ask-marvin
c
@Marvin does the open source version of prefect allow alerting via teams or slack?
m
thought for 141.7 seconds
Short answer: Yes. In open-source Prefect (Prefect Server, 3.x), you can send notifications to Slack and Microsoft Teams directly from your flows using the built-in notification blocks. What’s Cloud-only is Automations (i.e., point-and-click rules that trigger alerts on state changes without adding code). On Server/OSS, you add a small bit of code to send messages when you want (e.g., on failure). Key points: - OSS supports programmatic notifications via: - Slack:
prefect.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)
Copy code
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
Copy code
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.