---
title: Create an alert
description: Create a Databricks SQL alert, review its evaluation details, and customize advanced settings and notification templates.
canonical_url: https://docs.databricks.com/gcp/en/sql/user/alerts/create
---

# <a id="create-alert" />Create an alert

This page walks you through creating a Databricks SQL alert end-to-end. It covers the alert editor, the create-alert tutorial, how to review evaluation details, and the advanced settings and notification templates you can configure.

## <a id="editor-overview" />Explore the alert editor

The steps in this section walk you through how to create the alert shown in the following image. Use the labels and explanations to understand each component.

![The create alert UI is shown with numbered labels that identify different parts.](https://docs.databricks.com/gcp/en/images/dbsql-alerts/create-alert-ui.png)

1. **Query editor**: Write and test the query that you want to alert on.
2. **Compute**: Choose the SQL warehouse that runs the alert query. The status indicator shows whether the selected warehouse is running. For warehouse sizing recommendations and behavior at scheduled run time, see [Choose a SQL warehouse for an alert](https://docs.databricks.com/gcp/en/sql/user/alerts/compute.md).
3. **Schedule**: Set a periodic schedule for the alert to run.
4. **Share**: Set permissions that define how others in your workspace can work with your alert.
5. **Condition**: Select the value threshold that should trigger an alert notification. You can run the query to test the condition from this section.
6. **Notifications**: Indicate which users or notification destinations should be alerted when the threshold value falls outside of the expected range. Optionally, set a notification frequency to repeat notifications until the alert returns to `OK`.
7. **Advanced**: Use advanced settings to alert on special values and conditions.

## <a id="create-tutorial" />Create an alert

Use the following steps to create an alert:

1. Click ![Alerts Icon](https://docs.databricks.com/gcp/en/images/icons/alerts-icon.png) **Alerts** in the sidebar and click **Create Alert**.

2. Copy and paste the following query in the query editor. Click **Run all (1000)**. To learn more about working with the SQL editor, see [Databricks SQL editor](https://docs.databricks.com/gcp/en/sql/user/sql-editor/index.md).

   ```sql
   SELECT
     to_date(tpep_pickup_datetime) as date,
     SUM(fare_amount) as amount
   FROM
     `samples`.`nyctaxi`.`trips`
   GROUP BY
     ALL
   ORDER BY
     1 DESC

   ```

3. Click the compute selector, and then click a warehouse from the list to specify which compute resource runs the alert.

   ![The compute selector](https://docs.databricks.com/gcp/en/images/dbsql-alerts/compute-selector.png)

4. In the **Condition** field, set the conditions that should trigger the alert.

   ![Condition field with applied settings as in the following text.](https://docs.databricks.com/gcp/en/images/dbsql-alerts/condition.png)

   Apply the following settings as shown:

   * Select **Sum** as the data value to check. You can set an alert condition on the first value of a column in the query result, or you can select to set an aggregation across all rows of a single column, such as SUM or AVERAGE.
   * Select **amount** as the column to check.
   * Select **>** (greater than) as the logical operator to apply.
   * Set the threshold value to **`Static value`** 4000. **Static value** is selected by default. Enter 4000 into the value field.

5. Click **Test condition** to preview the alert and test whether the alert would trigger with the current data. The provided settings should trigger the alert. You can change the threshold value to test further.

6. In the **Notifications** section, search for your username and click it when it appears.

7. Click ![Calendar icon.](https://docs.databricks.com/gcp/en/images/product-icons/CalendarIcon.svg) the calendar icon to open the **Edit schedule** dialog. Use the drop-down menus to set the alert so that it runs **Every 5** **minutes** from **0 minutes past the hour**. Click **Save**.
   Optionally, select the **Show cron syntax** checkbox to edit the schedule in [Quartz Cron Syntax](http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html).

8. Click **View alert**.

Your alert is saved and runs on the schedule you provided. The data used in this example is static, so if your **Test condition** returned as **Triggered**, it triggers again the next time it runs. You receive an email notification as an alert. If the **Test condition** returned **OK**, no notification is sent.

## <a id="review-details" />Review alert details

A page opens to show your alert details. The page also shows an alert history with evaluation details. Click the **Run now** button to run the alert query immediately and return the result on this page.

Click **Edit** in the upper right corner of the page to continue editing the alert.

### <a id="investigate-an-alert-with-genie-code" />Investigate an alert with Genie Code

> [!NOTE]
> **Beta**
>
> This feature is in [Beta](https://docs.databricks.com/gcp/en/release-notes/release-types.md). To use it, a workspace admin must turn on the **Alertv2 Genie Analysis** preview. See [Configure Genie Code analysis](https://docs.databricks.com/gcp/en/sql/user/alerts/create.md#configure-genie-code-analysis).

After you configure Genie Code analysis for an alert, the analysis starts when the alert changes from another state to **Triggered** or **Error**. See [Configure Genie Code analysis](https://docs.databricks.com/gcp/en/sql/user/alerts/create.md#configure-genie-code-analysis). An evaluation that remains in the same state does not start another analysis. If starting the analysis fails or takes longer than 60 seconds, the alert evaluation and notifications continue without an investigation link.

After the analysis finishes, click **Investigate** for the evaluation in **History**. You can also open **Evaluation details** and click **Investigate**. Both links open the same Genie Code investigation.

Supported default notification templates can also include an investigation link. These templates include email, Microsoft Teams, PagerDuty, Slack Block Kit, and default webhooks. Legacy Slack attachments and custom webhook templates don't include the link.

The user whose credentials run the alert owns the generated Genie Code thread. An investigation link does not grant access, and alert permissions and thread permissions are separate. See [Configure alert permissions and transfer alert ownership](https://docs.databricks.com/gcp/en/sql/user/alerts/manage.md#alert-permissions). The thread owner must [share the chat thread](https://docs.databricks.com/gcp/en/genie-code/navigate-genie-code.md#share-chat) with recipients before they can open it. Generated investigations are read-only. To continue the investigation in an editable copy, click **Clone to continue**.

## <a id="concurrency-limits" />Workspace active run limits

Alert runs are subject to a workspace-level active run limit. Each workspace has a default limit of 250 simultaneous active alert runs. When all run slots are in use and a scheduled alert fires, the alert run is skipped and the alert does not evaluate.

If you suspect alerts are being skipped, check the evaluation history for gaps at the scheduled time. The most common pattern is that all affected alerts share the same schedule and a manual **Run now** succeeds because it runs outside the concurrency spike.

### Avoid hitting the active run limit

To reduce simultaneous demand on run slots, stagger alert schedules so they do not all fire at the same time. For example, instead of scheduling all alerts at `01:30`, schedule them at `01:30`, `01:32`, `01:34`, and so on.

### Request a quota increase

If your workspace consistently reaches the active run limit, contact [Databricks Support](https://www.databricks.com/support) to request an increase to your workspace's maximum active runs quota. Provide the workspace ID, the approximate time window when runs were skipped, and the total number of alerts affected.

## <a id="advanced-settings" />Advanced settings

Click **Advanced settings** to apply the following settings:

* **Notify on OK**: Send a notification when the alert returns as `OK`.
* **Empty result state**: Set a special status to return when the query returns no results.
* **Template**: Configure the notification template. See [Notification templates](https://docs.databricks.com/gcp/en/sql/user/alerts/create.md#notification-templates).

Workspace admins can set up new notification destinations. See [Manage notification destinations](https://docs.databricks.com/gcp/en/admin/workspace-settings/notification-destinations.md).

For the JSON body that an alert sends to a webhook notification destination, see [SQL alert webhook payload](https://docs.databricks.com/gcp/en/sql/user/alerts/webhook-payload.md).

### <a id="configure-genie-code-analysis" />Configure Genie Code analysis

> [!NOTE]
> **Beta**
>
> This feature is in [Beta](https://docs.databricks.com/gcp/en/release-notes/release-types.md). To use it, a workspace admin must turn on **Alertv2 Genie Analysis** from the **Previews** page. See [Manage Databricks previews](https://docs.databricks.com/gcp/en/admin/workspace-settings/manage-previews.md).

A workspace admin must enable the **Alertv2 Genie Analysis** preview before alert owners can configure the feature:

1. As a workspace admin, click your username in the top bar of the Databricks workspace and select **Previews**.
2. Turn on **Alertv2 Genie Analysis**.

See [ Manage workspace-level previews](https://docs.databricks.com/gcp/en/admin/workspace-settings/manage-previews.md#workspace).

To configure Genie Code analysis in the alert editor:

1. Click **Advanced settings**.
2. Select **Run Genie Code analysis on alert fire**.
3. Optionally, enter custom instructions for the investigation. Custom instructions replace the generic analysis instruction.
4. Click **View alert** to save the alert.

The alert is configured to start a new investigation when its state changes to **Triggered** or **Error**.

The analysis applies only to alerts that run as a user. Alerts that run as a [service principal](https://docs.databricks.com/gcp/en/admin/users-groups/service-principals.md) do not start an analysis. To check or change an alert's run-as identity, see [Configure the run-as identity](https://docs.databricks.com/gcp/en/sql/user/alerts/manage.md#run-as). See also [Investigate an alert with Genie Code](https://docs.databricks.com/gcp/en/sql/user/alerts/create.md#investigate-an-alert-with-genie-code).

### <a id="notification-templates" />Notification templates

Notifications use the default template unless you customize them. To customize the subject and body, select **Customize template**. Two editors are available: the standard editor and the Markdown editor. Click the tabs below to compare them.

#### Standard editor

In the standard editor, reference variables in the subject and body with `{{VARIABLE_NAME}}`. The following variables are supported:

* `ALERT_STATUS`: The evaluated alert status (string).
* `ALERT_CONDITION`: The alert condition operator (string).
* `ALERT_THRESHOLD`: The alert threshold (string or number).
* `ALERT_COLUMN`: The alert column name (string).
* `ALERT_NAME`: The alert name (string).
* `ALERT_URL`: The alert page URL (string).
* `QUERY_RESULT_TABLE`: The query result HTML table (string). Results are limited to the first 100 rows. Only email notification destinations can render HTML.
* `QUERY_RESULT_VALUE`: The query result value (string or number).
* `QUERY_RESULT_ROWS`: The query result rows (value array).
* `QUERY_RESULT_COLS`: The query result columns (string array).

For example: `Alert "{{ALERT_NAME}}" changed status to {{ALERT_STATUS}}`.

The standard editor also supports HTML for formatting. Only email notification destinations can render HTML. The following HTML tags are allowed: `<a>`, `<b>`, `<blockquote>`, `<br>`, `<code>`, `<del>`, `<div>`, `<em>`, `<h1>`, `<h2>`, `<h3>`, `<h4>`, `<h5>`, `<h6>`, `<hr>`, `<i>`, `<img>`, `<li>`, `<ol>`, `<p>`, `<pre>`, `<span>`, `<table>`, `<thead>`, `<tbody>`, `<td>`, `<th>`, `<tr>`, `<u>`, `<ul>`.

The following attributes are allowed on the listed tags:

| **Attribute** | **Supported tags**                                                              |
| ------------- | ------------------------------------------------------------------------------- |
| `href`        | `<a>`                                                                           |
| `title`       | `<img>`                                                                         |
| `target`      | `<a>`                                                                           |
| `alt`         | `<img>`                                                                         |
| `src`         | `<img>`                                                                         |
| `start`       | `<b>`, `<blockquote>`, `<code>`, `<del>`, `<em>`, `<hr>`, `<i>`, `<pre>`, `<u>` |

Click the **Preview** toggle button to preview the rendered result.

> [!IMPORTANT]
>
> The preview is useful for verifying that template variables are rendered correctly. It is not an accurate representation of the eventual notification content, because each notification destination can display notifications differently.

#### Markdown editor

Turn **Markdown Editor** on to write the body using Markdown. The Markdown editor has a formatting toolbar and a rendered preview.

In the Markdown editor, reference variables with `@VARIABLE_NAME`. Type `@` in the body to open the variable picker. The Markdown editor supports `ALERT_NAME`, `ALERT_STATUS`, `ALERT_CONDITION`, `ALERT_THRESHOLD`, `ALERT_COLUMN`, `ALERT_URL`, and `QUERY_RESULT_TABLE`.
