Guardrails API
Guardrails are rules the AI Gateway applies to a model's requests: to the text sent to the model
(input) and to what it returns (output). A rule can block the request, change the text (mask
personal data, replace words, truncate) or only log what it found. Each rule is made from a
template and carries that template's settings per direction. A model's guardrails are on or
off as a whole; turning them off keeps their rules.
Guardrails apply to chat, completion and multimodal models. All endpoints require
authentication via the X-API-Key header and the scope shown.
Templates
| Template | Directions | What it does |
|---|---|---|
pii-filter | input, output | Masks, blocks or logs personal data: SSNs, payment card numbers, emails, phone numbers, passport and driver's license numbers |
data-leak-prevention | input, output | Stops sensitive identifiers leaving in responses (the PII detectors, usually on output) |
toxicity-filter | input, output | Blocks, replaces or logs the toxic words, phrases and patterns you list |
prompt-injection | input, output | Blocks, replaces or logs the injection phrases and patterns you list |
content-filter | input, output | Blocks, replaces or logs the inappropriate words, phrases and patterns you list |
profanity-filter | input, output | Replaces, blocks or logs the profanity you list |
token-limit | input, output | Truncates or blocks text longer than a number of tokens or characters |
rate-limiter | input | Limits requests to the model per minute, hour and day, per user or shared |
hallucination-detector | output | A judge model you choose checks each answer's claims against the request's own context and blocks or logs an answer whose share of supported claims is below your threshold |
One more is listed with available: false and the reason: the gateway cannot enforce it yet
(language-filter). A rule that names it is refused.
Hallucination detector
The detector checks an answer for grounding in what the request gave the model, the
contextual-grounding check of LLM guardrails: the request's messages (the system prompt, user
and assistant turns, documents placed in them, tool results) are the context. The judge model
splits the answer into its factual claims (greetings, questions and refusals are not claims) and
says which of them the context states or directly implies. The answer's grounding score is
the share of its claims the context supports (an answer with no claim scores 1). Below the rule's
threshold the answer is blocked (400) or logged; the event records the score, the number of
claims and of unsupported claims, and the judge, never the text.
The judge is any chat model you may use other than the guarded model, chosen per rule
(GET /api/v1/ai-gateway/models/:id/guardrails/judge-models). Each check is a request to the
judge, recorded against the judge model like any other. A judge that answers without a verdict
per claim fails the request: the answer is never let through unchecked. A streamed answer whose
detector blocks is held until it has been checked.
Rule Object
{
"id": "rule-1",
"template": "pii-filter",
"name": "Mask personal data",
"enabled": true,
"priority": 1,
"config": {
"output": {
"enabled": true, "action": "mask", "mask_type": "char", "mask_char": "*", "mask_length": "full",
"detect_ssn": true, "detect_credit_card": true, "detect_email": true,
"detect_phone": false, "detect_passport": false, "detect_drivers_license": false
}
}
}
| Field | Type | Description |
|---|---|---|
id | string | Your id for the rule, unique among the model's rules |
template | string | An available template id |
name | string | Its name |
enabled | boolean | A disabled rule is kept and does nothing |
priority | number | Lower runs first |
config | object | The template's settings by direction (input, output, only those the template has); a rate limiter's settings are config itself |
Settings
Every setting of a template is given, in snake_case as the gateway reads it; an unknown or missing setting is refused, naming it.
| Templates | Settings |
|---|---|
pii-filter, data-leak-prevention | enabled; action: mask, block or log; mask_type: char, uuid or labeled_uuid; mask_char (one character); mask_length: full or partial; detect_ssn, detect_credit_card, detect_email, detect_phone, detect_passport, detect_drivers_license (booleans; an enabled block detects at least one) |
toxicity-filter, prompt-injection, content-filter, profanity-filter | enabled; keywords (words and phrases); regex_patterns; case_sensitive; action: block, modify (replace with replacement_text) or log; replacement_text (an enabled block has a keyword or a pattern) |
token-limit | enabled; max_tokens and max_characters (positive whole numbers or null; an enabled block has one); action: truncate or block; truncation_message |
rate-limiter | enabled; limits: { period: minute | hour | day, limit }, one per period; per_user (each user counted apart, or shared); burst_limit (or null); cooldown_minutes; error_message |
hallucination-detector (output) | enabled; judge_model_id (the judge model's id); threshold (the least share of supported claims that passes, above 0 and at most 1); action: block or log |
GET /api/v1/ai-gateway/guardrails/templates
The templates, each with its id, name, category, directions, description, available
and unavailableReason (null when available).
Scope: guardrails:read
Response 200 OK: every template, in one list.
GET /api/v1/ai-gateway/guardrails
The models whose requests guardrails can check, each with its guardrails, and the totals.
Scope: guardrails:read
Response 200 OK
{
"data": {
"models": [
{
"id": "2e4a85074d1cb2ea2d461843",
"name": "Support Chat",
"type": "third-party",
"provider": "openai",
"modelType": "chat",
"status": "active",
"canEdit": true,
"guardrails": {
"enabled": true, "rules": 2, "inputRules": 2, "outputRules": 1,
"blocked24h": 3, "modified24h": 12, "logged24h": 0,
"lastTriggered": "2026-10-11T08:12:00Z"
}
}
],
"totals": { "protectedModels": 1, "rules": 2, "blocked24h": 3, "modified24h": 12, "logged24h": 0 },
"since": "2026-10-10T09:00:00Z"
},
"meta": { "requestId": "req_abc123" }
}
The counts are of the last 24 hours (since). canEdit is whether you may change the model's
guardrails.
GET /api/v1/ai-gateway/guardrails/statistics
What guardrails did across your models in the last 24 hours: protectedModels, rules,
blocked24h, modified24h, logged24h and since.
Scope: guardrails:read
Response 200 OK
GET /api/v1/ai-gateway/models/:id/guardrails
A model's guardrails: modelId, enabled, its rules, updatedAt, updatedBy,
and the model it belongs to.
Scope: guardrails:read
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | The model |
Response 200 OK
PUT /api/v1/ai-gateway/models/:id/guardrails
Replace a model's guardrails with the state you give.
Scope: guardrails:write
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | The model |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
enabled | boolean | Yes | Whether the guardrails are on |
rules | array | Yes | Every rule the model is to have |
A rule whose template is unknown or unavailable, or whose settings the template cannot apply, is
refused with 400, naming the rule.
Response 200 OK: the model's guardrails, as GET shows them.
PATCH /api/v1/ai-gateway/models/:id/guardrails
Turn a model's guardrails on or off, keeping its rules.
Scope: guardrails:write
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | The model |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
enabled | boolean | Yes | true to turn them on, false to turn them off |
Response 200 OK: the model's guardrails.
POST /api/v1/ai-gateway/models/:id/guardrails/test
Run rules on a sample text exactly as the gateway applies them to requests, without a model
call. Nothing is recorded. Use it to check rules before saving them. A rate limiter counts
requests, not text, so it has no test (400).
Scope: guardrails:write
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | The model the rules are for |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
input | string | Yes | The sample text |
direction | string | Yes | input (sent to the model) or output (returned by it) |
rules | array | Yes | The rules to run |
grounding | string | With a hallucination-detector rule | The context the detector checks the text against (what the request sent the model); refused when no rule is a detector |
Response 200 OK: blocked (whether the rules block the text), modified (whether they
change it), output (the text after them) and events (each rule that fired, with its action
and findings).
GET /api/v1/ai-gateway/models/:id/guardrails/judge-models
The chat models that may judge the model's answers in a hallucination-detector rule: models
you may use, other than the model itself, each { id, name } (pass the id as
judge_model_id). A cursor-paged list.
Scope: guardrails:read
GET /api/v1/ai-gateway/models/:id/guardrail-logs
What a model's guardrails did, newest first unless sorted: one record per request and direction
in which a rule fired, with timestamp, userId, requestId, direction, blocked, modified and the
events.
Scope: guardrails:read
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | The model |
q | string | No | Only records whose direction, request id, user id, rule name or action contains this text |
sort | string | No | One of timestamp (default -timestamp), direction, outcome (blocked, then changed), userId, requestId; - for descending |
limit | integer | No | Results per page (default 50, at most 200) |
cursor | string | No | meta.nextCursor of the previous page |
Response 200 OK: a page of records, meta.nextCursor set while more remain.