Contact Us 1-800-596-4880

Regex Prompt Guard Policy

Policy Name

Regex Prompt Guard

Summary

Blocks LLM requests that match deny-list regex patterns

Category

LLM

First Omni Gateway version available

v1.11.4

Release Notes

Regex Prompt Guard Policy

Returned Status Codes

403 - Forbidden: Request blocked because prompt content matched one or more denied patterns

Summary

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 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

Omni Gateway Local Mode

The Regex Prompt Guard 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:

Element Required Description

Pattern Name

Yes

Human-readable pattern name. The policy includes this value in the blocked-response details.

Regex Pattern

Yes

RE2-style regex expression used to match prompt content. Use (?i) for case-insensitive matching. See the Summary section for supported and unsupported regex features.

Response on Block

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

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

Regex Support

The Regex Prompt Guard Policy uses the Rust regex crate 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