Skip to main content

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​

TemplateDirectionsWhat it does
pii-filterinput, outputMasks, blocks or logs personal data: SSNs, payment card numbers, emails, phone numbers, passport and driver's license numbers
data-leak-preventioninput, outputStops sensitive identifiers leaving in responses (the PII detectors, usually on output)
toxicity-filterinput, outputBlocks, replaces or logs the toxic words, phrases and patterns you list
prompt-injectioninput, outputBlocks, replaces or logs the injection phrases and patterns you list
content-filterinput, outputBlocks, replaces or logs the inappropriate words, phrases and patterns you list
profanity-filterinput, outputReplaces, blocks or logs the profanity you list
token-limitinput, outputTruncates or blocks text longer than a number of tokens or characters
rate-limiterinputLimits requests to the model per minute, hour and day, per user or shared
hallucination-detectoroutputA 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
}
}
}
FieldTypeDescription
idstringYour id for the rule, unique among the model's rules
templatestringAn available template id
namestringIts name
enabledbooleanA disabled rule is kept and does nothing
prioritynumberLower runs first
configobjectThe 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.

TemplatesSettings
pii-filter, data-leak-preventionenabled; 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-filterenabled; 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-limitenabled; max_tokens and max_characters (positive whole numbers or null; an enabled block has one); action: truncate or block; truncation_message
rate-limiterenabled; 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

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

ParameterTypeRequiredDescription
idstringYesThe model

Request Body

FieldTypeRequiredDescription
enabledbooleanYesWhether the guardrails are on
rulesarrayYesEvery 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

ParameterTypeRequiredDescription
idstringYesThe model

Request Body

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

ParameterTypeRequiredDescription
idstringYesThe model the rules are for

Request Body

FieldTypeRequiredDescription
inputstringYesThe sample text
directionstringYesinput (sent to the model) or output (returned by it)
rulesarrayYesThe rules to run
groundingstringWith a hallucination-detector ruleThe 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

ParameterTypeRequiredDescription
idstringYesThe model
qstringNoOnly records whose direction, request id, user id, rule name or action contains this text
sortstringNoOne of timestamp (default -timestamp), direction, outcome (blocked, then changed), userId, requestId; - for descending
limitintegerNoResults per page (default 50, at most 200)
cursorstringNometa.nextCursor of the previous page

Response 200 OK: a page of records, meta.nextCursor set while more remain.