Skip to main content

Guardrails

A guardrail profile is a reusable set of rules applied to prompts before they reach a provider and to answers before they reach the client. Models pick a profile on their Guardrails & logging tab; models without one use the default from AI Gateway › Settings.

Rules​

RuleOptions
Personal data in promptsAllow, Mask before sending (replaced with placeholders such as [REDACTED_EMAIL]), or Block the request (400 guardrail_blocked).
Personal data in responsesAllow or Mask before returning. Streaming answers are masked line by line.
DetectEmail addresses, card numbers (Luhn-checked), IBANs (checksum-checked), US SSNs, phone numbers.
Blocked patternsRegular expressions in Go RE2 syntax, one per line ((?i) makes them case-insensitive). A prompt matching any of them is blocked.
Max prompt charactersPrompts longer than this are blocked (0 = no limit).

External connectors​

A profile can also call external guardrail services. Add them under External connectors; each one has:

SettingMeaning
ChecksPrompts, answers, or both.
When it finds somethingBlock the request (400 guardrail_blocked), Flag it in AI Logs and continue, or Mask (Presidio only).
If the service is downAllow the request (default) or Block the request. Failures are logged without the checked text.
Endpoint, API keyWhere the service runs; keys are API key Credentials. If a connector's credential cannot be used (for example it was deleted), the connector fails without calling the service, and If the service is down decides whether the request continues or is blocked.
ThresholdPresidio: minimum confidence score. Azure and OpenAI: minimum score for a category to count (0 uses the service's own verdict).
ConnectorWhat it does
Microsoft PresidioSelf-hosted PII detection (POST {endpoint}/analyze). With Mask, each detected entity is replaced with [REDACTED_<ENTITY>] before the prompt is sent. Options: language (default en).
Lakera GuardPrompt injection and jailbreak detection (https://api.lakera.ai/v2/guard).
Azure AI Content SafetyHate, violence, sexual and self-harm categories. A category counts at severity 4 or higher by default; set Threshold or the severity option to change it.
OpenAI moderationOpenAI's moderation endpoint (omni-moderation-latest by default; option model).
WebhookYour own service. It receives {"stage", "text", "model", "client_id"} and answers {"flagged": true, "reason": "..."} or {"action": "block"}.
Zerq workflowRuns a Zerq workflow, named by exactly one of workflow_id (a workflow) or proxy_id (a proxy's workflow). A workflow that starts with Called by Workflow gets the check {"stage", "text", "model", "client_id"} as its input and its Return node's body is the verdict (status error fails the connector); one that starts with an HTTP trigger gets the check as the JSON body of a POST and its response node's body is the verdict. The verdict has the webhook's shape. The workflow runs only while it is active (a workflow) or its proxy's workflow is enabled; otherwise the connector fails. Workflow nodes run for real, so a workflow can call internal systems, look up a customer or open a ticket, or ask another model with an LLM node (nested workflow model calls through the AI Gateway stop after three levels, so a guardrail that calls its own model cannot loop).

Connectors check the messages that are new in this turn (everything after the last assistant message) and non-streamed answers. Streamed answers get the built-in masking only. Each connector times out after 5 seconds (option timeout_ms).

Workflow connector​

{ "type": "workflow", "stage": "input", "action": "block", "workflow_id": "<workflow id>", "enabled": true }

Saving a profile checks that a workflow connector has exactly one of workflow_id and proxy_id (and that only workflow connectors have a workflow_id). Existing connectors with proxy_id keep working.

In the console, add a Zerq workflow connector and pick it in Workflow. The list has two groups: Workflows (published workflows that start with Called by Workflow or Incoming request, saved as workflow_id; ones that are not active are marked off, and the connector fails until you activate them) and Proxy workflows (by route) (proxies whose workflow is enabled, saved as proxy_id). The console sends only the field you chose. A saved connector that names a workflow the list does not offer keeps its value and shows (not found).

Example verdict of a Called by Workflow guardrail, in its Return node's body:

{
"flagged": "{{ String($json['workflow_trigger_1'].input.text).toLowerCase().includes('wire transfer') }}",
"reason": "wire transfers need human approval"
}

Example workflow verdict of an HTTP trigger guardrail, in a response node's body:

{
"flagged": "{{ String($json.trigger.request.body.text).toLowerCase().includes('wire transfer') }}",
"reason": "wire transfers need human approval"
}

Try it​

The dialog's Try it panel runs the current settings (saved or not) against sample text as a prompt or as a response and shows whether it would pass, be masked, flagged or blocked, what was found, and the masked text. Nothing is sent to a model. Viewers can test the built-in rules; only modifiers can save.

Include external connectors (modifier role) also runs the profile's connectors, which call the services with the stored keys and run workflows for real. These tests are audited (ai_guardrail / test_connectors).

What gets logged​

Guardrail actions are recorded on each AI log entry (masked or blocked, the stage, the reason and counts per data type) and summed on the Overview page. With redacted logging, stored prompts and answers have personal data masked even when the guardrail allows it.