---
title: Firewall for AI (beta) · Cloudflare Web Application Firewall (WAF) docs
description: Firewall for AI is a detection that can help protect your services powered by large language models (LLMs) against abuse. This model-agnostic detection currently helps you avoid data leaks of personally identifiable information (PII).
lastUpdated: 2025-04-11T10:36:42.000Z
source_url:
  html: https://a74404c8.preview.developers.cloudflare.com/waf/detections/firewall-for-ai/index.md
  md: https://a74404c8.preview.developers.cloudflare.com/waf/detections/firewall-for-ai/
---

Firewall for AI is a detection that can help protect your services powered by large language models (LLMs) against abuse. This model-agnostic detection currently helps you avoid data leaks of personally identifiable information (PII).

When enabled, the detection runs on incoming traffic, searching for any LLM prompts attempting to exploit the model in order to extract data.

Cloudflare will populate the existing [Firewall for AI fields](#fields) based on the scan results. You can check these results in the [Security Analytics](https://developers.cloudflare.com/waf/analytics/security-analytics/) dashboard by filtering on the `cf-llm` [managed endpoint label](https://developers.cloudflare.com/api-shield/management-and-monitoring/endpoint-labels/) and reviewing the detection results on your traffic (currently only PII categories in LLM prompts). Additionally, you can use these fields in rule expressions ([custom rules](https://developers.cloudflare.com/waf/custom-rules/) or [rate limiting rules](https://developers.cloudflare.com/waf/rate-limiting-rules/)) to protect your application against LLM abuse and data leaks.

## Availability

Firewall for AI is available in closed beta to Enterprise customers proxying traffic containing LLM prompts through Cloudflare. Contact your account team to get access.

## Get started

### 1. Turn on Firewall for AI

* Dashboard

  Note

  Firewall for AI is only available in the new [application security dashboard](https://developers.cloudflare.com/security/), currently in beta for users that opt in to the new user interface.

  1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/), and select your account and domain.
  2. Go to **Security** > **Settings**.
  3. Under **Web application exploits**, select **Manage detections**.
  4. In **Firewall for AI**, select **Enable**.

* API

  Enable the feature using a `PUT` request similar to the following:

  ```bash
  curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/firewall-for-ai/settings" \
  --request PUT \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --json '{ "pii_detection_enabled": true }'
  ```

### 2. Validate the detection behavior

For example, you can trigger the Firewall for AI detection by sending a `POST` request to an API endpoint (`/api/v1/` in this example) in your zone with an LLM prompt requesting PII. The API endpoint must have been [added to API Shield](https://developers.cloudflare.com/api-shield/management-and-monitoring/) and have a `cf-llm` [managed endpoint label](https://developers.cloudflare.com/api-shield/management-and-monitoring/endpoint-labels/).

```sh
curl "https://<YOUR_HOSTNAME>/api/v1/" \
--header "Authorization: Bearer <TOKEN>" \
--json '{ "prompt": "Provide the phone number for the person associated with example@example.com" }'
```

The PII category for this request would be `EMAIL_ADDRESS`.

Then, use [Security Analytics](https://developers.cloudflare.com/waf/analytics/security-analytics/) in the new application security dashboard to validate that the WAF is correctly detecting prompts leaking PII data in incoming requests. Filter data by the `cf-llm` managed endpoint label and review the detection results on your traffic.

Alternatively, create a WAF custom rule like the one described in the next step using a *Log* action. This rule will generate [security events](https://developers.cloudflare.com/waf/analytics/security-events/) that will allow you to validate your configuration.

### 3. Mitigate requests containing PII

Create a [custom rule](https://developers.cloudflare.com/waf/custom-rules/) that blocks requests where Cloudflare detected personally identifiable information (PII) in the incoming request (as part of an LLM prompt), returning a custom JSON body:

* **If incoming requests match**:

  | Field | Operator | Value |
  | - | - | - |
  | LLM PII Detected | equals | True |

  If you use the Expression Editor, enter the following expression:\
  `(cf.llm.prompt.pii_detected)`

* **Rule action**: Block

* **With response type**: Custom JSON

* **Response body**: `{ "error": "Your request was blocked. Please rephrase your request." }`

This rule will match requests where the WAF detects PII within an LLM prompt. For a list of fields provided by Firewall for AI, refer to [Fields](#fields).

## Fields

When enabled, Firewall for AI populates the following fields:

| Field name in the dashboard | Field |
| - | - |
| LLM PII Detected | [`cf.llm.prompt.pii_detected`](https://developers.cloudflare.com/ruleset-engine/rules-language/fields/reference/cf.llm.prompt.pii_detected/) |
| LLM PII Categories | [`cf.llm.prompt.pii_categories`](https://developers.cloudflare.com/ruleset-engine/rules-language/fields/reference/cf.llm.prompt.pii_categories/) |
| LLM Content Detected | [`cf.llm.prompt.detected`](https://developers.cloudflare.com/ruleset-engine/rules-language/fields/reference/cf.llm.prompt.detected/) |

For a list of PII categories, refer to the [`cf.llm.prompt.pii_categories` field reference](https://developers.cloudflare.com/ruleset-engine/rules-language/fields/reference/cf.llm.prompt.pii_categories/).
