Guardrails
Block, redact or flag prompt injection, secrets, personal data, harmful content and your own rules, per account, workspace, member or key.
A guardrail is a named safety policy on your account. It checks what goes to the model and what comes back, and it can block (a 403, nothing billed), redact (the match becomes a placeholder such as [redacted:secret]) or flag (let it through and record the hit). Assign one to the whole account, or to chosen workspaces, members or keys, under Guardrails in the dashboard. It covers /chat/completions, /messages, /responses and batches; your code does not change.
When several guardrails cover one request, all of their policies run and the strictest action wins: block, then redact, then flag. On the way in, every message is checked (system, user, assistant, tool results and earlier tool-call arguments), including text taken from an attached PDF or audio. On the way out, the assistant's text is checked; tool-call arguments and reasoning are not.
stage is input for the prompt and output for the reply. A moderation or Prompt Guard check that cannot run (the classifier is down, or the request is held to a region it has no route in) lets the request through and records the hit as unavailable, unless the policy sets fail_closed, which refuses with 503 guardrail_unavailable instead.
HTTP 403
{
"ok": false,
"error": {
"code": "guardrail_blocked",
"message": "Blocked by guardrail 'Production safety': prompt injection (ignore previous instructions). Nothing was sent to the model and nothing was billed.",
"guardrail": {
"id": "gr_...",
"name": "Production safety",
"policy": "injection",
"rule": "ignore previous instructions",
"stage": "input"
}
}
}Streams
A stream with a check on the reply is held until it ends, checked, then sent as it was, redacted, or withheld with an error event in your stream's own format. Keep-alive comments still go out while it is held, so the connection stays open, but the first token arrives with the last. Checks on the prompt only do not hold a stream.
Billing
Pattern checks (injection, secrets, personal data, custom rules) are free. Moderation and the Prompt Guard second opinion call a classifier; each call is its own row in your logs, billed at that model's catalogue price, and not billed on a :free request. A prompt blocked on the way in is not billed, since nothing reached the model. A reply withheld on the way out is billed, because the model generated it; the error says so.
Region
Under provider: { region: "in" } the moderation and Prompt Guard classifiers have no India route, so they count as unable to run (see fail_closed above). Every other policy runs on our own servers and works under a region.
The same guardrails can be managed in code with your dashboard session. An organisation owner or admin can add ?account_id= to manage the account the organisation belongs to.
Limits: 25 guardrails per account, 50 custom rules per guardrail, 200 characters per pattern, 50 allowlist phrases. A regular expression with a backreference, a lookbehind or a quantified group that contains a quantifier is refused. The first 200,000 characters of a request are checked; moderation reads the last 24,000, where the newest messages are.
curl https://rapidrouter.ai/api/v1/guardrails \
-H "Authorization: Bearer <session JWT>" \
-H "Content-Type: application/json" \
-d '{
"name": "Production safety",
"assign": { "all": false, "workspaces": ["ws_..."], "members": [], "keys": [] },
"policies": {
"injection": { "enabled": true, "action": "block", "model_check": false, "allow": [] },
"secrets": { "enabled": true, "action": "redact", "on": ["input", "output"] },
"pii": { "enabled": true, "action": "redact", "types": ["email", "phone", "pan", "aadhaar"], "on": ["input"] },
"moderation": { "enabled": false, "action": "block", "categories": ["S1", "S9", "S10", "S11"], "on": ["input", "output"], "fail_closed": false },
"custom": { "enabled": true, "rules": [
{ "id": "r1", "name": "No competitor names", "match": "phrase", "pattern": "acme corp", "action": "block", "on": ["input", "output"] }
] }
}
}'