<@ULVA73B9P> I Want to create notification using p...
# ask-marvin
h
@Marvin I Want to create notification using prefect UI,that will send me a slack message when the lateness of the task exceed 5 minutes
m
thought for 103.3 seconds
Yes — in Prefect Cloud, you can create a Slack notification in the UI for flow run lateness over 5 minutes. Important caveat: this applies to flow runs / deployments, not individual task runs. ### What you need 1. A Slack Webhook notification block 2. An Automation in Prefect Cloud 3. A lateness condition of 5 minutes ### Best way: use a deployment SLA + automation This is the clearest setup if you want “alert me when this scheduled run starts more than 5 minutes late”. #### 1) Add a lateness SLA to your deployment You define a lateness SLA of 5 minutes on the deployment. Example:
Copy code
`
from datetime import timedelta
from prefect import flow
from prefect._experimental.sla.objects import LatenessSla

@flow
def my_flow():
    pass

my_flow.from_source(
    source="<https://github.com/owner/repo>",
    entrypoint="flows.py:my_flow",
).deploy(
    name="my-deployment",
    work_pool_name="my-pool",
    _sla=[
        LatenessSla(
            name="late-by-5-minutes",
            within=timedelta(minutes=5),
            severity="high",
        )
    ],
)
`
#### 2) Create a Slack webhook block in the UI In Prefect Cloud: - Go to Blocks - Create a Slack Webhook block - Paste your Slack incoming webhook URL - Save it #### 3) Create the automation in the UI In Prefect Cloud: - Go to Automations - Click New Automation - Choose an Event trigger - Set the event to: -
prefect.sla.violation
Then add an action: - Send notification - Select your Slack Webhook block Example message: - Subject:
Flow run late: {{ event.resource.name }}
- Body:
A flow run exceeded the 5-minute lateness SLA.
### If you want to do this fully from the UI only You can create the Slack block and the automation in the UI, but the lateness SLA itself is typically defined on the deployment. ### Important clarification If you literally mean task lateness: - Prefect does not provide this as a standard UI lateness notification feature for task runs - The built-in lateness/SLA path is for flow runs ### Helpful docs - Automations - Notifications - SLAs - Prefect Cloud If you want, I can also show you: - a pure UI walkthrough step-by-step, or - how to alert on flow run state instead if “lateness” isn’t quite what you need.
h
I have the slack webhook, saved in the prefect block. so using a block will send the message to that channel in case of conitioning full fill?
@Marvin I have the slack webhook, saved in the prefect block. so using a block will send the message to that channel in case of conitioning full fill?
m
thought for 12.3 seconds
Yes — if your automation action uses that Slack Webhook block, Prefect will send the notification to the Slack channel configured by that webhook when the trigger condition is met. So the flow is: 1. Trigger condition happens Example: SLA violation / lateness event 2. Automation fires 3. Send notification action uses your saved Slack Webhook block 4. Slack posts to the channel tied to that webhook URL A couple of important notes: - The channel is determined by the Slack webhook, not by Prefect - Prefect just sends the message payload to that webhook - If the webhook is valid and the automation triggers, the message should appear in that Slack destination ### In short Yes: the block is the destination/config for Slack delivery, and Prefect will use it when the condition is satisfied. ### Good idea to verify You may want to: - confirm the automation is enabled - confirm the trigger is matching the right event - send a test event if available in your setup - check whether the webhook is still active in Slack ### One subtle point Having the block saved alone does not send messages. You still need: - a trigger (automation condition) - an action = Send notification - that action configured to use your Slack Webhook block If you want, I can show you the exact UI fields to fill in for: - lateness over 5 minutes, or - a simpler flow run failed -> Slack notification.
h
@Marvin what should be the body to test, ihave selected the block wihcih contain url webhook current template Subject Prefect deployment '{{ flow.name }}/{{ deployment.name }}' has entered status '{{ deployment.status }}' Body: Name: {{ flow.name }}/{{ deployment.name }} Status: {{ deployment.status }} URL: {{ deployment|ui_url }}
m
thought for 14.4 seconds
Yes — that template is fine if your automation is triggered by a deployment status event and those variables exist in that event context. For a simple test, you can use a very basic body like:
Copy code
`
This is a test notification from Prefect.

Flow: {{ flow.name }}
Deployment: {{ deployment.name }}
Status: {{ deployment.status }}
URL: {{ deployment|ui_url }}
`
And subject:
Copy code
`
Test notification: {{ flow.name }}/{{ deployment.name }}
`
### Important warning Those template variables only work if the trigger provides them. If your automation is not a deployment-status event,
flow.name
,
deployment.name
, or
deployment.status
may not render. ### Safer generic test template If you just want to confirm Slack delivery, use a more generic event-based template: Subject
Copy code
`
Prefect notification test
`
Body
Copy code
`
This is a test notification from Prefect.

Event: {{ event.event }}
Resource: {{ event.resource.name }}
Occurred: {{ event.occurred }}
`
That is usually safer for automations driven by events. ### For SLA/lateness notifications If your trigger is based on lateness / SLA violation, use something more like: Subject
Copy code
`
Flow run late: {{ event.resource.name }}
`
Body
Copy code
`
A Prefect SLA violation was detected.

Flow run: {{ event.resource.name }}
Event: {{ event.event }}
Occurred: {{ event.occurred }}
`
### Recommendation If your goal is just testing the Slack webhook block, use plain text with minimal templating first: Subject
Copy code
`
Prefect Slack test
`
Body
Copy code
`
Hello from Prefect. This is a test notification.
`
If that works, then switch to templated fields. If you want, I can help you build the exact subject/body for your specific automation trigger type.