---
schema_version: "1"
id: 980c12036468d96871704e5b925dda1acb158b230e92feca2be1d893d86010ff
title: LLM PII Detection Policy
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/gateway/1.13/policies-included-llm-pii-detection.md
canonical_url: https://docs.mulesoft.com/gateway/1.13/policies-included-llm-pii-detection
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 9d9073576b95bfc4322d0d87a6231acef685d69675c219ebcf18d389a568eb0b
description: MuleSoft Documentation Site
release: "1.13"
latest: false
---
---
product: Omni Gateway
version: 1.13
keywords: api gateway, flex gateway, gateway, policy, llm, pii, personally identifiable information
---

# LLM PII Detection Policy

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

<table><colgroup><col> <col></colgroup><tbody><tr><td><p><strong>Policy Name</strong></p></td><td><p>LLM PII Detection Policy</p></td></tr><tr><td><p><strong>Summary</strong></p></td><td><p>Detects personally identifiable information (PII) in OpenAI and Anthropic format LLM requests and responses</p></td></tr><tr><td><p><strong>Category</strong></p></td><td><p>LLM</p></td></tr><tr><td><p><strong>First Omni Gateway version available</strong></p></td><td><p>v1.13.0</p></td></tr><tr><td><p><strong>Release Notes</strong></p></td><td><p><a href="https://docs.mulesoft.com/release-notes/gateway/policies/llm-pii-detection-release-notes">LLM PII Detection</a></p></td></tr><tr><td><p><strong>Returned Status Codes</strong></p></td><td><p>403 - Forbidden</p></td></tr></tbody></table>

## Summary

The LLM Personally Identifiable Information (PII) Detection policy scans OpenAI and Anthropic format
Model Proxy traffic for PII.

The policy inspects incoming request bodies and outgoing response bodies for PII.

When PII is detected, the policy reports a policy violation. For request traffic, you configure
whether to reject the request, log findings, or log masked findings. Response traffic is never
blocked.

## Configuring Policy Parameters

### Omni Gateway Local Mode

The LLM PII Detection policy isn’t supported in Local Mode.

### Managed Omni Gateway and Omni Gateway Connected Mode

When you apply the policy from the UI, the following parameters are displayed:

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Element</th><th>Required</th><th>Description</th></tr></thead><tbody><tr><td><div><div><p>PII Types</p></div></div></td><td><div><div><p>Yes</p></div></div></td><td><div><div><p>Array of built-in PII types to detect. Supported values are <strong>Email</strong>, <strong>US SSN</strong>, <strong>Credit Card</strong>, and <strong>Phone Number</strong>. For more information, see <a href="#pii-types">PII Types</a>.</p></div></div></td></tr><tr><td><div><div><p>Custom PII Patterns</p></div></div></td><td><div><div><p>No</p></div></div></td><td><div><div><p>Array of custom regex patterns to detect additional sensitive values. Define a name and regex pattern for each array entry. For example, use <code>name: AWS Access Key</code> and <code>pattern: AKIA[0-9A-Z]{16}</code> to detect AWS access keys.</p></div></div></td></tr><tr><td><div><div><p>Action</p></div></div></td><td><div><div><p>No</p></div></div></td><td><div><div><p>Action to take when PII is detected in a request. Supported values are <strong>Reject</strong>, <strong>Log</strong>, and <strong>Log and mask</strong>. Default is <strong>Log</strong>.</p></div></div></td></tr></tbody></table>

## How This Policy Works

The policy scans OpenAI and Anthropic format JSON body traffic. It recursively inspects all string
values in the JSON body, including all conversation messages. The policy only inspects requests
whose method is `POST`.

For request processing:

- If **Action** is **Reject**, the policy blocks the request and returns HTTP `403`.

- If **Action** is **Log** or **Log and mask**, the policy forwards the request and logs findings.

For response processing:

- The policy scans JSON responses and logs findings.

- Responses are not blocked, regardless of action.

## PII Types

When you configure the LLM PII Detection policy, choose which types of PII to detect.

<table><colgroup><col> <col></colgroup><thead><tr><th>PII Type</th><th>Description</th></tr></thead><tbody><tr><td><div><div><p>Email</p></div></div></td><td><div><div><p>Standard email addresses such as <code>User.Name+tag@example.com</code>.</p></div></div></td></tr><tr><td><div><div><p>US SSN</p></div></div></td><td><div><div><p>United States Social Security Numbers (SSNs), including formats with various delimiters such as <code>123-45-6789</code>, <code>123 45 6789</code>, <code>123.45.6789</code>, <code>123,45,6789</code>, <code>123/45/6789</code>, <code>123\45\6789</code>, or <code>123456789</code>.</p></div></div></td></tr><tr><td><div><div><p>Credit Card</p></div></div></td><td><div><div><p>Credit card numbers for Visa, MasterCard, American Express, and Discover, with or without separators. Examples: <code>4111-1111-1111-1111</code>, <code>4111 1111 1111 1111</code>, <code>4111111111111111</code>, <code>4111.1111.1111.1111</code>, <code>5500-0000-0000-0004</code>, <code>3782-822463-10005</code>, <code>6011-0000-0000-0004</code>.</p></div></div></td></tr><tr><td><div><div><p>Phone Number</p></div></div></td><td><div><div><p>Phone numbers in common domestic and international formats based on ITU E.164 country codes. Examples include US numbers like <code>(555) 123-4567</code>, <code>555-123-4567</code>, <code>+1-555-123-4567</code>, and international numbers like <code>+91 98765 43210</code>, <code>+44 20 7946 0958</code>, <code>+49 30 12345678</code>.</p></div></div></td></tr></tbody></table>

## Response on Reject

When the policy blocks a request, it returns a `403` response with this structure:

```json
{
  "error": {
    "message": "Request contains PII data: <findings>",
    "type": "pii_detected"
  }
}
```

## Example Request and Logging

This example shows a request containing PII and the corresponding log output for different action
configurations.

```http
POST /v1/chat/completions HTTP/1.1
Content-Type: application/json

{
  "model": "gemini/gemini-2.5-flash",
  "messages": [
    {"role": "user", "content": "Look up the account for SSN 123-45-6789 and email john@example.com"},
    {"role": "user", "content": "Look up the account for credit card 4123 8171 5881 9171"},
    {"role": "user", "content": "hello"}
  ]
}
```

- Log

- Log and Mask

When the action is set to **Log**, the policy logs detected PII with the actual values:

```json
[accessLog]  PII detected in LLM request (log only): [
  {
    "pii_type": "SSN",
    "value": "123-45-6789",
    "start": 28,
    "end": 39
  },
  {
    "pii_type": "Email",
    "value": "john@example.com",
    "start": 50,
    "end": 66
  },
  {
    "pii_type": "CreditCard",
    "value": "4123 8171 5881 9171",
    "start": 31,
    "end": 50
  }
]
```

When the action is set to **Log and mask**, the policy logs detected PII with masked values:

```json
[accessLog]  PII detected in LLM request (log only): [
  {
    "pii_type": "SSN",
    "masked_value": "***-**-*789",
    "start": 28,
    "end": 39
  },
  {
    "pii_type": "Email",
    "masked_value": "****@example.com",
    "start": 50,
    "end": 66
  },
  {
    "pii_type": "CreditCard",
    "masked_value": "*************171",
    "start": 31,
    "end": 50
  }
]
```

### Custom Pattern Example

This example shows detection of a custom AWS Access Key pattern:

```http
POST /v1/chat/completions HTTP/1.1
Content-Type: application/json

{
  "model": "gemini/gemini-2.5-flash",
  "messages": [
    {"role": "user", "content": "Use this AWS key: AKIAIOSFODNN7EXAMPLE for deployment"}
  ]
}
```

With a custom pattern configured (`name: AWS Access Key`, `pattern: AKIA[0-9A-Z]{16}`), the policy
logs:

```json
[accessLog] PII detected in LLM request (log only): [
  {
    "pii_type": "AWS Access Key",
    "masked_value": "********************",
    "start": 19,
    "end": 39
  }
]
```

## See Also

- [Creating and Managing Model Proxies](https://docs.mulesoft.com/general/model-proxy)

- [Regex Prompt Guard](https://docs.mulesoft.com/gateway/1.13/policies-included-regex-prompt-guard)

- [LLM Token Based Rate Limit](https://docs.mulesoft.com/gateway/1.13/policies-included-llm-token-rate-limit)
