Skip to main content
The ai.promptGuard policy inspects LLM request prompts and/or model responses before they are forwarded. Guards can be applied to request (incoming user prompts) and response (model output) independently. Multiple guards can be chained in each list. ai.promptGuard is part of the ai policy, which marks a route as LLM traffic:
binds:
- port: 3000
  listeners:
  - routes:
    - policies:
        ai:
          promptGuard:
            request:
            - regex:
                action: reject
                rules:
                - pattern: SSN
            response:
            - bedrockGuardrails:
                guardrailIdentifier: my-guardrail
                guardrailVersion: DRAFT
                region: us-west-2

Guard types

Each item in request[] or response[] is exactly one of the following guard types:
Inspect content using regular expression patterns. Supports both custom patterns and built-in named patterns for common PII types.
regex
object
Regex-based content guard.
Example — reject requests containing PII:
ai:
  promptGuard:
    request:
    - regex:
        action: reject
        rules:
        - pattern: SSN
        - pattern: Social Security
      rejection:
        status: 400
        headers:
          set:
            content-type: "application/json"
        body: |
          {
            "error": {
              "message": "Request rejected: Content contains sensitive information",
              "type": "invalid_request_error",
              "code": "content_policy_violation"
            }
          }
    - regex:
        action: reject
        rules:
        - builtin: email
      rejection:
        status: 400
        body: '{"error": {"message": "Contains email address"}}'

Rejection configuration

Each guard entry can include a rejection block that customizes the HTTP response returned when the guard denies a request.
rejection
object
Configures the HTTP response sent to the client when the guard rejects a request.

Guard chaining

Multiple guards can be listed under request[] or response[]. Guards are evaluated in order. If any guard rejects the content, the associated rejection response is returned immediately and subsequent guards are not evaluated.
ai:
  promptGuard:
    request:
    - regex:                  # evaluated first
        action: reject
        rules:
        - pattern: SSN
      rejection:
        status: 400
        body: 'Rejected: contains SSN'
    - regex:                  # evaluated second (only if first passes)
        action: reject
        rules:
        - builtin: email
      rejection:
        status: 400
        body: 'Rejected: contains email'
The ai.promptGuard policy only applies to routes that process LLM traffic. The parent ai policy must be set on the route for prompt guard to take effect.