---
schema_version: "1"
id: 704a91a6ac983af22dfb3b5d4c32c622d8cc9aaa4be8ecf4c5f93f3a4ccf7fc8
title: Regex Prompt Guard Policy
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/gateway/1.12/policies-included-regex-prompt-guard.md
canonical_url: https://docs.mulesoft.com/gateway/1.12/policies-included-regex-prompt-guard
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 85dee0a17cfb4cce3e07b731c2ca2fe827aa2a5df65935770bee6fd5f0f73f78
description: MuleSoft Documentation Site
release: "1.12"
latest: false
---
---
product: Omni Gateway
version: 1.12
keywords: api gateway, flex gateway, gateway, policy, llm, prompt guard, regex, prompt injection
---

# Regex Prompt Guard 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>Regex Prompt Guard</p></td></tr><tr><td><p><strong>Summary</strong></p></td><td><p>Blocks LLM requests that match deny-list regex patterns</p></td></tr><tr><td><p><strong>Category</strong></p></td><td><p>LLM</p></td></tr><tr><td><p><strong>First Flex Gateway version available</strong></p></td><td><p>v1.11.4</p></td></tr><tr><td><p><strong>Returned Status Codes</strong></p></td><td><p>403 - Forbidden: Request blocked because prompt content matched one or more denied patterns</p></td></tr></tbody></table>

## Summary

> [!NOTE] This policy supports OpenAI and Anthropic input formats.

The Regex Prompt Guard policy scans LLM prompts and blocks requests when prompt content matches
regex deny-list patterns.

The policy uses the Rust [regex crate](https://crates.io/crates/regex) which supports RE2-style
expressions to guarantee linear-time matching and eliminate the backtracking risk.

For example, you can use the policy to block attacks such as:

- Prompt injection

- Jailbreak attempts

- SQL injection patterns

- HTML script injection

## Configuring Policy Parameters

### Flex Gateway Local Mode

The Regex Prompt Guard policy isn’t supported in Local Mode.

### Managed Flex Gateway and Flex 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>Pattern Name</p></div></div></td><td><div><div><p>Yes</p></div></div></td><td><div><div><p>Human-readable pattern name. The policy includes this value in the blocked-response details.</p></div></div></td></tr><tr><td><div><div><p>Regex Pattern</p></div></div></td><td><div><div><p>Yes</p></div></div></td><td><div><div><p>Regex expression used to match prompt content. Use <code>(?i)</code> for case-insensitive matching. See the Regex Support section for supported and unsupported regex features.</p></div></div></td></tr></tbody></table>

## Response on Block

When a request is blocked, the policy returns a response body containing the matched deny patterns:

```json
{
  "error": "Request blocked - content matches denied pattern",
  "matched_patterns": ["prompt-injection"]
}
```

## Regex Support

The Regex Prompt Guard Policy uses the Rust [regex crate](https://crates.io/crates/regex) which
supports RE2-style expressions to guarantee linear-time matching and eliminate the backtracking
risk. This ensures that customer-supplied regex patterns can’t negatively impact gateway performance
or availability.

The Regex Prompt Guard policy doesn’t support Perl Compatible Regular Expressions (PCRE), but
supports these PCRE features:

- Standard character classes

- Alternation

- Grouping

- Greedy or lazy quantifiers

- Anchors

- Inline flags, such as `(?i)`, for case-insensitivity.

These PCRE-specific features aren’t supported:

- Lookaround assertions: `(?=…​)`, `(?!…​)`, `(?⇐…​)`, `(?<!…​)`

- Backreferences: `\1`, `\2`, `(?P=name)`

- Recursive or subroutine calls: `(?R)`, `(?1)`

- Possessive quantifiers: ``a*`, `a+``

- Special constructs: `\G`, `\K`, and conditional patterns `(?(1)yes|no)`

## See Also

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

- [LLM Token Based Rate Limit Policy](https://docs.mulesoft.com/gateway/1.12/policies-included-llm-token-rate-limit) - Token-based rate
  limiting for Model Proxy
