Choosing a Guardrail Provider
Guardrails enforce content policy before a request reaches an upstream model, after the model responds, or at both hook points. Choose a guardrail based on where content can be evaluated, what it must detect, and whether matching content should be blocked or masked.
The same gateway guardrails are available in AISIX Enterprise, AISIX Cloud, and AISIX OSS, and all three products scope a guardrail the same way: an attachment binds it to an environment or to selected resources, and a guardrail nothing attaches inspects no traffic. The control plane writes the attachment when you pick a scope; the resources file declares it in a guardrail_attachments collection.
In AISIX Enterprise and AISIX Cloud, the dashboard's guardrail forms offer every configuration field the gateway reads for each kind, including Presidio's per-entity actions and score threshold, OpenAI Moderation's per-category thresholds, the output failure policy and stream buffer settings of Lakera and Presidio, and the window settings of both Alibaba Cloud kinds. Saving a guardrail from the dashboard keeps every config field the form does not display, such as window settings stored on a guardrail in buffer_full mode, while clearing a field on the form removes it. The Admin API works as before: a PATCH that includes config replaces the whole object, so send back every field you want to keep.
Before configuring a provider, establish the policy boundaries that apply to your traffic:
| Question | Reference |
|---|---|
| When does the guardrail run, and which traffic does it cover? | Guardrail Policy Behavior |
| Which routes and fields can AISIX inspect or mask? | Guardrail Content Coverage |
| How does output inspection affect a streamed response? | Streaming Guardrail Behavior |
| What happens when AISIX cannot complete a check? | Guardrail Failure Handling |
After choosing these boundaries, follow the provider guide for configuration and verification.
Provider Comparison
Use the comparison to identify where a guardrail evaluates content and whether it supports the action your policy requires:
| Kind | Provider | Evaluation Location | Detects | Actions |
|---|---|---|---|---|
keyword | Built-in | Inside AISIX | Literal and regular-expression patterns | Block |
semantic | Built-in | AISIX compares embeddings locally; selected text is sent to the configured embedding model endpoint | Text semantically similar to your examples, including reworded attempts that share no keywords | Block |
pii | Built-in | Inside AISIX | Rule-based PII, such as email addresses, phone numbers, IDs, cards, keys, and custom patterns | Mask or block |
presidio | Presidio | Self-hosted Presidio service | Rule-based and NER/ML PII entities, such as PERSON and LOCATION | Mask with replace, mask, hash, or redact operators; or block |
lakera | Lakera Guard | Lakera API | Prompt injection, jailbreaks, unsafe content, and PII | Block; mask PII-only detections |
azure_content_safety | Azure AI Content Safety | Azure API | Prompt injection and jailbreaks through Prompt Shield | Block |
azure_content_safety_text_moderation | Azure AI Content Safety | Azure API | Hate, sexual, self-harm, and violence severity categories, plus blocklists | Block |
openai_moderation | OpenAI Moderation | OpenAI API | Harassment, hate, violence, sexual, self-harm, and other content categories | Block |
bedrock | AWS Bedrock Guardrails | AWS Bedrock service | Content filters, denied topics, sensitive information, and word filters | Block; mask PII configured with ANONYMIZE |
aliyun_text_moderation | Alibaba Cloud Content Moderation | Alibaba Cloud API | Risk-level content moderation | Block |
aliyun_ai_guardrail | Alibaba Cloud AI Guardrails | Alibaba Cloud API | Console-policy composite checks: content compliance, prompt attacks, and sensitive data | Block; mask sensitive data per console policy |
custom | Your own script | Wherever your script calls, from inside your gateway | Whatever you implement, for a screening service AISIX has no built-in integration with | Block or mask, as your script decides |
Every listed guardrail can inspect caller requests, model responses, or both. Guardrail Policy Behavior explains their shared hooks, scope, priority, and enforcement mode.
Choose a Guardrail by Goal
After narrowing the available providers, match the policy goal to a practical starting point:
| Goal | Start With | Consider Also |
|---|---|---|
| Detect or redact PII | Built-in PII, which runs inside AISIX and supports rule-based detectors plus custom patterns. | Presidio for entities that regular expressions cannot express, such as names, locations, or nationalities. Presidio also supports self-hosted evaluation and hash or placeholder replacement. Consider AWS Bedrock or Lakera when you already use those providers. |
| Detect prompt injection and jailbreaks | Lakera Guard or Azure Prompt Shield. | Attach both when a security review requires independent providers. Both can screen indirect injection carried in retrieved documents or tool results included in a conversation. |
| Moderate content categories | OpenAI Moderation for its standard category set. | Azure Text Moderation for per-category severity thresholds and server-side blocklists, or the Alibaba Cloud guardrails within that provider ecosystem — AI Guardrails for console-managed composite policy with sensitive-data masking, Content Moderation for AISIX-side risk thresholds. |
| Enforce organization-specific rules | Built-in keyword guardrail. | Match literal or regular-expression patterns without an external dependency. |
| Catch attempts that are rephrased to evade a pattern list | Built-in semantic screening guardrail. | Match by meaning rather than wording; candidate texts from one hook are sent in one batched embedding request. |
| Screen against a service AISIX has no integration with | Custom script guardrail. | Write the translation as a script the gateway runs, rather than deploying an adapter service in front of your own. See Qwen3Guard Guardrails for a worked example that screens with an open-source guard model you run yourself, and TypeSafe Jev Guardrails for one that screens requests with a hosted decision model. |
Detection-based guardrails can produce false positives and false negatives, so evaluate a new policy in monitor mode before enforcing it on production traffic. See Guardrail Policy Behavior.
What the Gateway Records
Usage records identify applied guardrails, monitor-mode observations, blocked decisions, and the fail-open bypass reason. On every route that runs guardrails, applied_guardrails names the policies that governed the request. AISIX records this field whether the request succeeded, failed, or was refused. Every route's usage event also contains the bypass-reason field. See Interpret Bypass Reasons.
A guardrail's own refusal does not contain the matched value: the error the caller receives and the usage event's error_message carry policy wording and the guardrail's name. Guardrail-specific fields in usage records created by gateways with the current telemetry behavior do not copy the matched body or script-provided reasons and counts.
Upgrading the gateway does not redact data in existing usage records. Older records may still contain sensitive data in reasons or counts returned by custom guardrail scripts. Restrict access to those records, including any exported copies.
Other text can still carry a matched value. In monitor mode the content passes through, so an upstream error that echoes it reaches error_message and the access log. A validation error raised before guardrails run can quote a value in the same places. error_message is metadata, so it reaches the control plane's store and every exporter under content_mode: metadata_only as well. See Read an Upstream Error Message.
An exporter with content_mode: full carries request bodies on failure rows. That includes the text that triggered a block, and a row that failed before guardrails finished carries the body unmasked. Protect that destination as content-bearing; see Protect Failure Content.
Operator logs can include the matched literal or regular-expression rule for a built-in keyword block. The provider guides show the redaction tokens and block-response shapes for each guardrail kind.