> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreweave.com/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

[Try in Colab](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 starts to blow up (reports NaN) or a step in your ML pipeline completes. Alerts apply to all projects where you initialize runs, including both personal and team projects.

And then see W\&B Alerts messages in Slack (or your email):

![Slack alert setup](https://mintcdn.com/coreweave-dbfa0e8d/3Dv_sw2eg8feUJlx/products/wandb/_media/send_alerts_slack.png?fit=max\&auto=format\&n=3Dv_sw2eg8feUJlx\&q=85\&s=3739fea03fd05adb2a76cbd8d20514b0)

> [!NOTE]
>
> W\&B Alerts require you to add `run.alert()` to your code. Without modifying your code, [Automations](https://docs.coreweave.com/products/wandb/automations.md) provide another way to notify Slack based on an event in Weights & Biases, such as when an [artifact](https://docs.coreweave.com/products/wandb/artifacts.md) artifact version is created or when a [run metric](https://docs.coreweave.com/products/wandb/runs.md) meets or changes by a threshold.
>
> For example, an automation can notify a Slack channel when a new version is created, run an automated testing webhook when the `production` alias is added to an artifact, or start a validation job only when a run's `loss` is within acceptable bounds.
>
> Read the [Automations overview](https://docs.coreweave.com/products/wandb/automations.md) or [create an automation](https://docs.coreweave.com/products/wandb/automations/create-automations.md).

> [!NOTE]
>
> The following guide only applies to alerts in Multi-tenant Cloud.
>
> If you're using [W\&B Server](https://docs.coreweave.com/products/wandb/platform/hosting.md) in your Private Cloud or on W\&B Dedicated Cloud, refer to [Configure Slack alerts in W\&B Server](https://docs.coreweave.com/products/wandb/platform/hosting/monitoring-usage/slack-alerts.md) to set up Slack alerts.

## Automated run lifecycle alerts

Weights & Biases can notify you when a run finishes or crashes, without any code changes. In your [User settings](https://forge.coreweave.com/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()`](https://docs.coreweave.com/products/wandb/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** page. 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 [User settings](https://forge.coreweave.com/settings).
2. Add `run.alert()` to your code.
3. Test the configuration.

### 1. Turn on alerts in your user settings

In your [User settings](https://forge.coreweave.com/settings):

* 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. We recommend the **Slackbot** channel because it keeps the alerts private.
* **Email** will go to the email address you used when you signed up for Forge. We recommend setting up a filter in your email so all these alerts go into a folder and don't fill up your inbox.

You will only have to do this the first time you set up W\&B Alerts, or when you'd like to modify how you receive alerts.

![Alerts settings in User settings](https://mintcdn.com/coreweave-dbfa0e8d/3Dv_sw2eg8feUJlx/products/wandb/_media/demo_connect_slack.png?fit=max\&auto=format\&n=3Dv_sw2eg8feUJlx\&q=85\&s=447031fea4fc850c58c6910d1aa6059d)

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

Add `run.alert()` to your code (either in a Notebook or Python script) wherever you'd like it to be triggered

```python theme={"system"}
import wandb

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

### 3. Test the configuration

Check your Slack or emails for the alert message. If you didn't receive any, make sure you've got emails or Slack turned on for **Scriptable Alerts** in your [User settings](https://forge.coreweave.com/settings)

## Example

This simple alert sends a warning when accuracy falls below a threshold. In this example, it only sends alerts at least 5 minutes apart.

```python theme={"system"}
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

Use the at sign `@` followed by the Slack user ID to tag yourself or your colleagues in either the title or the text of the alert. You can find a Slack user ID from their Slack profile page.

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

## Configure team alerts

Team admins can set up alerts for the team on the team settings page: `wandb.ai/teams/your-team`.

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

## Change Slack channel to send alerts to

To change what channel alerts are sent to, click **Disconnect Slack** and then reconnect. After you reconnect, pick a different Slack channel.
