> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-style-guide-models-runs-20260604-113608.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Send alerts, triggered from your Python code, to your Slack or email

# Send an alert

export const ColabLink = ({url}) => <a href={url} target="_blank" rel="noopener noreferrer" className="colab-link">
    <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
      <path d="M14.25.18l.9.2.73.26.59.3.45.32.34.34.25.34.16.33.1.3.04.26.02.2-.01.13V8.5l-.05.63-.13.55-.21.46-.26.38-.3.31-.33.25-.35.19-.35.14-.33.1-.3.07-.26.04-.21.02H8.77l-.69.05-.59.14-.5.22-.41.27-.33.32-.27.35-.2.36-.15.37-.1.35-.07.32-.04.27-.02.21v3.06H3.17l-.21-.03-.28-.07-.32-.12-.35-.18-.36-.26-.36-.36-.35-.46-.32-.59-.28-.73-.21-.88-.14-1.05-.05-1.23.06-1.22.16-1.04.24-.87.32-.71.36-.57.4-.44.42-.33.42-.24.4-.16.36-.1.32-.05.24-.01h.16l.06.01h8.16v-.83H6.18l-.01-2.75-.02-.37.05-.34.11-.31.17-.28.25-.26.31-.23.38-.2.44-.18.51-.15.58-.12.64-.1.71-.06.77-.04.84-.02 1.27.05zm-6.3 1.98l-.23.33-.08.41.08.41.23.34.33.22.41.09.41-.09.33-.22.23-.34.08-.41-.08-.41-.23-.33-.33-.22-.41-.09-.41.09zm13.09 3.95l.28.06.32.12.35.18.36.27.36.35.35.47.32.59.28.73.21.88.14 1.04.05 1.23-.06 1.23-.16 1.04-.24.86-.32.71-.36.57-.4.45-.42.33-.42.24-.4.16-.36.09-.32.05-.24.02-.16-.01h-8.22v.82h5.84l.01 2.76.02.36-.05.34-.11.31-.17.29-.25.25-.31.24-.38.2-.44.17-.51.15-.58.13-.64.09-.71.07-.77.04-.84.01-1.27-.04-1.07-.14-.9-.2-.73-.25-.59-.3-.45-.33-.34-.34-.25-.34-.16-.33-.1-.3-.04-.25-.02-.2.01-.13v-5.34l.05-.64.13-.54.21-.46.26-.38.3-.32.33-.24.35-.2.35-.14.33-.1.3-.06.26-.04.21-.02.13-.01h5.84l.69-.05.59-.14.5-.21.41-.28.33-.32.27-.35.2-.36.15-.36.1-.35.07-.32.04-.28.02-.21V6.07h2.09l.14.01.21.03zm-6.47 14.25l-.23.33-.08.41.08.41.23.33.33.23.41.08.41-.08.33-.23.23-.33.08-.41-.08-.41-.23-.33-.33-.23-.41-.08-.41.08z" />
    </svg>
    Try in Colab
  </a>;

<ColabLink url="https://wandb.me/alerts-colab" />

Create alerts with Slack or email if your run crashes or with a custom trigger. For example, you can create an alert if the gradient of your training loop reports `NaN`. You can also create an alert when a step in your ML pipeline completes. Alerts let you respond to training issues without continually watching the dashboard. Alerts apply to all projects where you initialize runs, including personal and team projects.

After you configure alerts, W\&B Alerts messages appear in Slack or your email:

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-style-guide-models-runs-20260604-113608/t3KPvpRCBt_2Z2XF/images/track/send_alerts_slack.png?fit=max&auto=format&n=t3KPvpRCBt_2Z2XF&q=85&s=b2204f37581d164d7b9d391b8aa2e5d7" alt="Slack alert setup" width="567" height="331" data-path="images/track/send_alerts_slack.png" />
</Frame>

<Note>
  W\&B Alerts require you to add `run.alert()` to your code. Without modifying your code, [Automations](/models/automations/) provide another way to notify Slack based on an event in W\&B, such as when W\&B creates an [artifact](/models/artifacts/) version or when a [run metric](/models/runs/) meets or changes by a threshold.

  For example, an automation can notify a Slack channel when W\&B creates a new version. It can run an automated testing webhook when you add the `production` alias to an artifact. It can also start a validation job only when a run's `loss` is within acceptable bounds.

  To create an automation, see [Create an automation](/models/automations/create-automations/).
</Note>

<Note>
  The following guide only applies to alerts in Multi-tenant Cloud.

  If you're using [W\&B Server](/platform/hosting/) in your Private Cloud or on W\&B Dedicated Cloud, refer to [Configure Slack alerts in W\&B Server](/platform/hosting/monitoring-usage/slack-alerts) to set up Slack alerts.
</Note>

## Automated run lifecycle alerts

W\&B can notify you when a run finishes or crashes, without any code changes. In your [User Settings](https://wandb.ai/settings), scroll to the **Alerts** section and turn on:

* **Run finished** to be notified when a run completes successfully.
* **Run crashed** to be notified when a run exits without calling [`run.finish()`](/models/ref/python/experiments/run#finish).

These toggles are per-user. **Run finished** alerts do not fire for runs in Jupyter notebooks. In notebooks, use `run.alert()` for completion notifications.

Alerts are delivered to email or Slack, configured in the same User Settings panel. The delivery setup is shared with scriptable alerts, which are covered in the following sections and let you trigger alerts on custom conditions such as a metric threshold or a NaN loss.

To set up scriptable alerts with `run.alert()`, take these steps, which are detailed in the following sections:

1. Turn on **Alerts** in your W\&B [User Settings](https://wandb.ai/settings).
2. Add `run.alert()` to your code.
3. Test the configuration.

### Turn on alerts in your W\&B user settings

This step enables the alert delivery channels (Slack or email) that `run.alert()` calls use. You only have to do this the first time you set up W\&B Alerts, or when you want to modify how you receive alerts.

In your [User Settings](https://wandb.ai/settings), configure the following:

* Scroll to the **Alerts** section.
* Turn on **Scriptable run alerts** to receive alerts from `run.alert()`.
* Use **Connect Slack** to pick a Slack channel to post alerts. W\&B recommends the **Slackbot** channel because it keeps alerts private.
* **Email** goes to the email address you used when you signed up for W\&B. W\&B recommends setting up a filter in your email so that all these alerts go into a folder and don't fill your inbox.

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-style-guide-models-runs-20260604-113608/mKqtgtuWRbdgi0HI/images/track/demo_connect_slack.png?fit=max&auto=format&n=mKqtgtuWRbdgi0HI&q=85&s=06caf6d861feb036d131cba1615f360f" alt="Alerts settings in W&B User Settings" width="1420" height="900" data-path="images/track/demo_connect_slack.png" />
</Frame>

After you complete these settings, W\&B can deliver alerts to your chosen channels whenever your code calls `run.alert()`.

### Add `run.alert()` to your code

This step sets the condition that triggers an alert and the message that the alert sends. Add `run.alert()` to your notebook or Python script where you want to send an alert.

```python theme={null}
import wandb

with wandb.init() as run:
    run.alert(title="High Loss", text="Loss is increasing rapidly")
```

### Test the configuration

Run your code to trigger the alert, then check Slack or your email for the alert message. If you don't receive the alert, make sure email or Slack notifications are turned on for Scriptable run alerts in your [User Settings](https://wandb.ai/settings).

After you complete these steps, your runs can notify you through Slack or email whenever the conditions you specify in `run.alert()` are met.

## Example alert

The following example shows a typical `run.alert()` pattern: it monitors a metric and sends a warning when accuracy falls below a threshold. It sends alerts no more than once every 5 minutes.

```python theme={null}
import wandb
from wandb import AlertLevel

with wandb.init() as run:

    if acc < threshold:
        run.alert(
            title="Low accuracy",
            text=f"Accuracy {acc} is below the acceptable threshold {threshold}",
            level=AlertLevel.WARN,
            wait_duration=300,
        )
```

## Tag or mention users

Tag users to direct alerts to the right person and trigger Slack's standard mention notifications. To tag yourself or a colleague, use the at sign `@` followed by the Slack user ID in the alert title or text. You can find a Slack user ID from their Slack profile page.

```python theme={null}
run.alert(title="Loss is NaN", text=f"Hey <@U1234ABCD> loss has gone to NaN")
```

## Configure team alerts

In addition to individual alerts, team admins can configure alerts that apply to everyone on the team. Team admins can set up team alerts on the team settings page: `wandb.ai/teams/[YOUR-TEAM]`.

Team alerts apply to everyone on your team. W\&B recommends using the **Slackbot** channel because it keeps alerts private.

## Change the Slack channel for alerts

To redirect alerts to a different Slack channel, click **Disconnect Slack** and then reconnect. After you reconnect, pick a different Slack channel.
