> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/ai-sre/ai-sre-for-administrators/set-up-alert-management/alert-rules/use-cel-alert-rules.md).

# Use CEL Expressions in Alert Rules

Use CEL expressions to match alert titles, combine multiple conditions, and skip alerts in alert rule conditions.

CEL (Common Expression Language) expressions provide advanced conditional logic for alert rule conditions beyond simple field comparisons.

CEL expressions cannot be tested or previewed before they execute. Syntax errors in a field name or function only appear as a configuration error on the alert timeline when an alert arrives. Send a test alert after each change.

{% hint style="info" %}
**FEATURE FLAG REQUIRED**

CEL expression mode requires the `IR_CEL_CONDITIONS` feature flag. Contact your Harness account team to enable this feature.
{% endhint %}

### When to use CEL expressions to route alerts <a href="#when-to-use-cel-expressions-to-route-alerts" id="when-to-use-cel-expressions-to-route-alerts"></a>

Use CEL expressions when you need:

* **Multi-phrase matching**: Page on any of several title patterns, such as `Kafka` plus `critical`
* **Complex boolean logic**: Combine multiple conditions with custom precedence
* **String operations**: Check if alert titles contain specific text
* **Exclusions**: Skip alerts whose title contains words like `Canceled` or `Close`

***

### Available alert data in CEL expressions <a href="#available-alert-data-in-cel-expressions" id="available-alert-data-in-cel-expressions"></a>

In an alert rule, the alert is the `Activity` namespace. Write fields as `Activity.<field id>`. The namespace name is not case sensitive, but field ids are lowercase and must match exactly.

{% hint style="warning" %}
There is no `alert` namespace. An expression that starts with `alert.title` fails every time it runs with "Error evaluating alert rule, invalid syntax" on the alert timeline, and the alert is never paged. Use `Activity.title`.
{% endhint %}

**Standard alert fields**:

```cel
Activity.title               // Alert title
Activity.description         // Alert description
Activity.priority.id            // p1_critical, p2_error, p3_warning, p4_info
Activity.status              // Alert status, such as triggered or acknowledged
Activity.deduplication_id    // Deduplication ID mapped from the incoming payload
Activity.monitoring_link     // Link to the alert in the source system
Activity.started_at          // When the alert started
```

The variables available in an alert rule are the fields defined on the alert template, so the list on your alert template is the source of truth. To stop repeated alerts from one monitor from opening new alerts, map the Deduplication ID field when you configure the integration. Go to [Create a webhook](https://developer.harness.io/ai-sre/ai-sre-for-administrators/set-up-alert-management/webhooks/create-webhook.md#map-fields-to-alert-properties) to map it.

**Custom alert fields**:

Fields you add to the alert template are available by their field id. Custom field ids can include a numeric suffix, for example `Activity.app_name_1793302543460`. Copy the exact id from the alert template.

***

### CEL alert rule examples <a href="#cel-alert-rule-examples" id="cel-alert-rule-examples"></a>

**Page on a keyword in the title**:

```cel
Activity.title.contains("Kafka")
```

**Case-insensitive match**:

```cel
Activity.title.lowerAscii().contains("kafka")
```

**Critical alerts only**:

```cel
Activity.priority.id == "p1_critical"
```

**Several title patterns**:

```cel
Activity.title.contains("timeout") || Activity.title.contains("connection refused")
```

**Two phrases that must both appear**:

```cel
Activity.title.lowerAscii().contains("kafka") && Activity.title.lowerAscii().contains("critical")
```

**Match title patterns and skip closes and cancels**:

```cel
(Activity.title.lowerAscii().contains("kafka") && Activity.title.lowerAscii().contains("critical")) &&
  !Activity.title.contains("Canceled") && !Activity.title.contains("Close")
```

***

### CEL operators to route alerts <a href="#cel-operators-to-route-alerts" id="cel-operators-to-route-alerts"></a>

**Comparison**:

```cel
==   Equal to
!=   Not equal to
```

**Logical**:

```cel
&&   AND
||   OR
!    NOT
```

**String operations**:

```cel
Activity.title.contains("text")         // Contains substring
Activity.title.startsWith("prefix")     // Starts with
Activity.title.endsWith("suffix")       // Ends with
Activity.title.lowerAscii()             // Lowercase, for case-insensitive checks
```

{% hint style="warning" %}
`matches()` is rejected when alert rules evaluate today, even for a one-word pattern, and the alert fails with "Error evaluating alert rule, invalid syntax". Rewrite regex alternatives as `contains()` checks joined with `||`. Keep the whole expression under 4,096 characters.
{% endhint %}

***

### Field-based conditions versus CEL <a href="#field-based-conditions-versus-cel" id="field-based-conditions-versus-cel"></a>

**Field-based conditions example**:

* Field: priority
* Operator: equals
* Value: p1\_critical

**Equivalent CEL expression**:

```cel
Activity.priority.id == "p1_critical"
```

**CEL advantages**:

* Several phrases in one rule, joined with `||` and `&&`
* Exclusions with `!`
* Flexible string operations
* Custom precedence with parentheses

***

### Best practices for CEL in alert rules <a href="#best-practices-for-cel-in-alert-rules" id="best-practices-for-cel-in-alert-rules"></a>

**1. Start small and add one condition at a time**:

Start with `Activity.title.contains("Kafka")`, send a test alert, and confirm it pages. Then add the next condition and test again. A rule that fails to evaluate never pages, and the only signal is a configuration error on the alert timeline.

**2. Use explicit parentheses**:

```cel
// Clear precedence
(Activity.title.contains("Kafka") || Activity.title.contains("AMQ")) &&
  !Activity.title.contains("Close")
```

**3. Match case-insensitively with `lowerAscii()`**:

```cel
Activity.title.lowerAscii().contains("critical")
```

**4. Test with sample alerts**:

* Send one alert that should page and one that should not through the webhook
* Check the alert timeline for "Error evaluating alert rule, invalid syntax"
* Send a new alert after each change, because rules evaluate when the alert is created

***

### Troubleshooting CEL in alert rules <a href="#troubleshooting-cel-in-alert-rules" id="troubleshooting-cel-in-alert-rules"></a>

<details>

<summary>Alerts never page and the timeline shows "Error evaluating alert rule, invalid syntax"</summary>

Check that every field starts with `Activity.`, not `alert.`. Then check for `matches()`, single = instead of ==, unclosed strings, missing parentheses, and typos in field ids. When a rule fails to evaluate, it counts as not matching and AI SRE moves on to the next rule.

</details>

<details>

<summary>Field not found errors in alert rule CEL expression</summary>

Verify the field id matches the alert template exactly. Field ids are lowercase, and custom fields can have a numeric suffix.

</details>

<details>

<summary>Expression is accepted but a matching alert does not page</summary>

Rules are checked in order and the first match wins, so an earlier rule can take the alert. Also check that the rule has a responder under Paging, and that the alert is not in quiet mode or already closed.

</details>

***

### Next steps <a href="#next-steps" id="next-steps"></a>

* Go to [Create Dynamic Content](https://developer.harness.io/ai-sre/ai-sre-for-administrators/get-started/expression-languages.md) for complete CEL syntax reference, additional operators, and advanced patterns
* Go to [Route Alerts](https://developer.harness.io/ai-sre/ai-sre-for-administrators/set-up-alert-management/alert-rules/overview.md) to learn about alert rule configuration
* Go to [Ingest Alerts](https://developer.harness.io/ai-sre/ai-sre-for-administrators/set-up-alert-management/webhooks/overview.md) to set up incoming alert sources

## FAQs <a href="#faqs" id="faqs"></a>

<details>

<summary>How do I stop repeated alerts from the same monitor from opening new alerts?</summary>

AI SRE has no fingerprint field. Alert deduplication works through the Deduplication ID field (`deduplication_id`), which you map from the incoming payload when you configure the integration, usually to whatever the source calls its monitor or check ID.

On ingest, AI SRE looks for an alert on the same alert template with the same Deduplication ID. If it finds one, the incoming payload updates that alert instead of creating a second one, so a flapping monitor produces a single alert with a rising update count. Deduplication ID appears on the alert details panel, and incidents have the same field.

There is no time window on the match. For alerts, the match is scoped to open statuses, so once an alert is closed, the next payload with the same Deduplication ID creates a new alert, however long the gap. Closing the alert is the boundary, not a clock. Incidents match on Deduplication ID regardless of status.

Correlation Tag and Correlation Duration are a separate feature that groups related alerts. Go to [Create a webhook](https://developer.harness.io/ai-sre/ai-sre-for-administrators/set-up-alert-management/webhooks/create-webhook.md#map-fields-to-alert-properties) to configure them.

</details>

{% hint style="info" %}
**Need Help?** Contact our support team by email at **<support@harness.io>** or visit the [Harness Documentation](https://docs.harness.io) for additional resources and troubleshooting guides.
{% endhint %}

{% @harness-feedback/feedback %}
