Docs/Budget Ai/Guardrails

Guardrails

Budget AI can inspect agent and application traffic inline with the same policies as AI Guardrails. When inspection is on, the gateway checks each chat completion request before it reaches the model, and each response before the caller receives it or, for streamed responses, while it streams. Agents and applications get this with no code change: they keep calling the gateway with their Budget AI key.

Inspection uses the same detectors and per-category actions as the ANTS SDK and the Portkey connector, so a policy behaves the same way whichever path the traffic takes.

Inspection is off by default at every level: the organization, the project and the key.

⚠

In the current release, the Budget AI guardrail controls are hidden in the app: the AI Guardrails card in Project Settings → Budget AI, the AI Guardrails column and row action on Budget AI → Keys, and guardrail refusals on the Refusals card of Budget AI → Overview. They cannot be changed in the app for now. The gateway still applies the project and key settings already saved, so inspection that was on stays on and inspected traffic is still checked, refused and recorded as described on this page. Guardrail policies are still managed in Governance → AI Guardrails.

What you need

RequirementWhereWho
The AI Guardrails feature is on for the organizationOrganization Settings → Features → Feature visibilitytenantSecurity.features:admin (Owner and Security & Compliance among the built-in roles)
A guardrail policy with Real-time Enforcement onGovernance → AI GuardrailsAI Guardrails write access
Inspection turned on for the project, or for individual keysProject Settings → Budget AI → AI Guardrails, and the key's AI Guardrails action on Budget AI → KeysgatewayAi.settings:admin (Owner and Budget AI Owner)
The detection service is available to the gatewayDeployment settingYour ANTS administrator
ℹ

Your ANTS deployment must have AI Guardrails scanning turned on for the Budget AI gateway; ask your ANTS administrator. Until it is, only the rule-based detectors run: Secrets & Credentials, Source Code and the card number and SSN checks (see Without the detection service). Every other part of the inspection ends as "not finished" and follows the project's failure setting: requests are forwarded and recorded as such, or refused with 503. Self-hosted deployments turn it on with Helm.

While the organization feature is off, no AI Guardrails settings, columns or actions appear anywhere in Budget AI, the settings cannot be changed through the API, and the gateway never inspects traffic, even for a key set to Always inspect. Turning the feature off keeps every project and key setting; turning it back on restores them as they were. The change reaches the gateway within about 2 seconds, and at most 60 seconds.

When inspection applies

Each key has an AI Guardrails mode. Inspection runs for a request when the organization feature is on and:

Key modeProject switch offProject switch on
Use the project setting (default)Not inspectedInspected
Always inspectInspectedInspected
Never inspectNot inspectedNot inspected

Every key, including keys minted through the API, starts as Use the project setting. Rotation carries the mode over to the new key. Traffic on keys that are not inspected is served exactly as before.

Which policy applies

  1. The guardrail policy of the agent the key is bound to, if that policy has Real-time Enforcement on.
  2. Otherwise, the project's Policy for keys without an agent, chosen in Project Settings → Budget AI → AI Guardrails. Only policies with Real-time Enforcement on are listed. Choosing one needs AI Guardrails read access as well.
  3. Otherwise, no policy applies. The request is served without content inspection and the trace records no_policy. This happens whatever the failure setting is, so choose a policy for keys without an agent if every key must be inspected.

Policies are created and edited in Governance → AI Guardrails, and a change applies to gateway, SDK and Portkey traffic alike. The gateway picks up a policy change within a few seconds. Detection categories and per-category actions are described in AI Guardrails. Custom detectors switched on for the agent run in Budget AI too.

What is inspected

ContentInspected
Text of system and developer messages (the system prompt)Yes
Text of every user, tool and function message, including text parts of multi-part contentYes
Text of the responseYes, for streamed and non-streamed responses
Tool calls in the request history and in the response, with their argumentsYes, against the agent's tool permissions, see Tool calls
Earlier assistant turns in the request historyNo
Tool definitions (tools)No
File uploads, images, audio and other non-text contentNo. Only text is inspected.
/v1/embeddings requestsNo

Long text is inspected in overlapping windows, so a long conversation or response is inspected in full and a value near the end is found as reliably as one near the start. The rule-based detectors (Secrets & Credentials, Source Code and the card number and SSN checks) are not windowed: they run once on the full text, up to 1 MiB, before the detection service is called.

Long conversations. Each message that the inspection let through unchanged, with no finding or with Audit Only or Warn findings only, is remembered for an hour for that policy. Later requests in the same conversation inspect only the new or changed messages, so a long conversation costs about the same as a short one, and a value pasted once does not raise a new detection on every later turn. A message that was blocked or redacted, or whose inspection did not finish, is never remembered, so Redact and Block apply to it every time. One consequence: an attack split across several earlier turns that each inspected clean on their own is not re-examined as a whole.

Requests with n above 1 are refused with 400 guardrail_unsupported_request when inspection applies, because only one choice can be inspected. Inspected requests bypass the response cache, so an uninspected cached answer is never served and a masked one is never stored.

Actions

Each detection category in the policy has its own action, and the strictest result wins. See Actions.

ActionOn the requestOn a non-streamed responseOn a streamed response
Audit OnlyRecorded; the request is sent unchangedRecorded; returned unchangedRecorded; streamed unchanged
WarnSent unchanged; the response carries the x-ants-guardrail-warning headerReturned unchanged with the same headerStreamed unchanged; the categories arrive in a final SSE comment, see What the caller sees
RedactDetected values are masked in place and the masked request is what the model receives. The system prompt, earlier turns, images and the order of parts are kept.The masked response is what the caller receivesDepends on the streaming mode: masked in Hold until scanned; ends the stream in Scan while streaming
BlockRefused with 400 guardrail_blocked; the model is never calledWithheld; the caller receives 400 guardrail_response_blockedEnds the stream with an error event, see Streamed responses

Redact masks values it can locate, such as PII, PCI and PHI entities and custom detector matches. A finding that cannot be masked, such as an Ethics & Bias or Safety detection under Redact, blocks instead. If a masked request cannot be mapped back onto the original messages, it is blocked rather than forwarded unmasked.

A blocked request is refused after its rate limits and budgets are checked, and its reservation is released, so it uses no tokens or budget. A blocked response has already been generated, so its usage is counted and billed like any other.

Tool calls outside the agent's declared tools

When the agent has approved tools, the gateway checks the tool calls in the request history (what the agent already called) and in the response (what the model asks it to call) against the agent's tool permissions: the tool is approved and its approval has not expired, its arguments follow the argument rules and contain no secrets, card numbers or social security numbers, and its calls per minute are within the limit. The agent is the key's bound agent, otherwise the agent of the policy for keys without an agent.

SituationResult
The policy blocks or redactsA call that breaks a rule is refused: 400 guardrail_blocked for a request, guardrail_response_blocked for a response. The message names the tools.
The policy's action is Audit Only, or the agent has no policyThe call is recorded in AI Violations and allowed
The agent has no approved toolsTool calls are not checked

Blocking is opt-in: give the agent a policy set to Block or Redact. The refusal message starts with, for example, "This call used tools outside the agent's declared tools:", "This call used tool arguments outside the agent's rules:" or "This call sent sensitive data to a tool:", followed by the tools. Names are compared ignoring case.

  • Rate limits are counted on responses, per agent and tool across all gateways.
  • Group-limited tools are always a violation on the gateway, because it does not know which user the agent acts for.
  • Approvals. When the policy blocks or redacts and a tool in the response needs a person's approval, the response is refused with "Approval is required before this agent can use: ... A request was created. Retry after it is approved." The request appears on the Approvals tab of the agent's profile and expires after 15 minutes. Once it is approved, the next call of that tool with the same arguments goes through, once. See Approvals.
  • Streamed responses. Tool names are checked as they arrive. Arguments, rate limits and approvals are checked when the stream ends.

Tool calls are checked only on requests that AI Guardrails inspection applies to. Approve an agent's tools on the Tools tab of its agent profile in Evidence Collection; see Declare the agent's tools. The agent needs a governance profile. A change reaches the gateways within a few seconds.

ℹ

The gateway checks the tool calls that pass through it. It does not stop an agent from running a tool on its own. To check tools inside the agent's code, use the ANTS SDKs.

Streamed responses

The request of a streamed call is always inspected before the model is called. For the response, choose a mode under Streamed responses in Project Settings → Budget AI → AI Guardrails:

ModeHow it worksTrade-off
Scan while streaming (default)Chunks are forwarded as they arrive. About every 1,000 new characters, the text since the last inspected point is inspected in overlapping pieces, so a value split across chunks is still seen whole. Everything left is inspected before [DONE] is sent. Tool calls are checked as their names arrive.No added wait for the first token. Text is sent before its piece is inspected, so on a Block some text, typically up to about 1,000 characters, may already have reached the caller. Sent text cannot be masked, so a Redact result also ends the stream.
Hold until scannedThe whole response is collected, tool calls are checked and the text is inspected, then it is sent unchanged, sent masked, or refused.Nothing uninspected is sent and Redact works, but the caller sees no tokens until the whole response has been generated and inspected.

On a Block or Redact in Scan while streaming, the gateway stops the provider call and ends the stream with an error event and [DONE].

Rule-based checks on each chunk (Scan while streaming). Before each chunk of the response is sent, the gateway runs the rule-based detectors on the new text, with the last 2,048 characters before it. When a Secrets & Credentials, Source Code, card number or SSN finding has the action Block or Redact, the stream stops before that chunk is sent, under either failure setting. A value is matched only once it is complete, so when a secret is split across chunks, the chunks that carry its beginning may already have been sent when the stream stops. Use Hold until scanned for keys where no part of a secret may reach the caller.

Keeping up with fast providers (Scan while streaming). The text that has been sent but not yet inspected may never exceed 32,768 characters. If the provider outruns the detectors by more than that:

  • With Refuse the request, the gateway pauses forwarding, and reading from the provider, until inspection catches up, sending : keepalive SSE comments every 10 seconds while paused. Every character is inspected and [DONE] is never sent before the whole text has passed. Only a single burst of more than eight times the limit is refused outright.
  • With Forward the request, the rest of the stream is passed through uninspected and the trace records fail_open:scan_backlog.

Once an inspection in a stream fails open, the rest of that stream is not inspected and the trace records why, so a stalled detection service costs one time limit per stream, not one per piece.

Long waits (Hold until scanned). So that load balancers do not close an idle connection, the gateway sends the response headers and a : keepalive SSE comment every 10 seconds while it waits. A response over 1,000,000 characters cannot be held: with Refuse the request it is refused, and with Forward the request it is passed through uninspected and recorded as fail_open:buffer_overflow.

With inspection on, a stream is re-sent as standard data: events. OpenAI SDKs handle it as usual.

With the cloud detection engine

When your deployment uses the cloud provider (AWS Comprehend and an LLM judge) instead of the self-hosted models, the gateway inspects as above, with these differences:

  • Audit Only categories run in the background. Categories whose action is Audit Only are checked in the background, so the request never waits for them. Their findings are still recorded.
  • Time limit. The judge is given the time left in the inspection time limit, so its fallback model can answer within it. With Safety on Block, a request waits for Comprehend and then the judge; keep Time limit for inspection at 2,000 ms or more for Block policies.
  • Streamed responses. Chunks are inspected without the judged categories (PHI, Ethics & Bias, Safety, Denied Topics and Hallucination). When the stream ends, the full reply is judged once in the background, as Audit Only, because it has already been sent.
  • Prompt injection. Tool outputs after the last assistant message are judged for prompt injection, and when a request has at least two user messages, the last six (up to 8,000 characters) are judged together for a jailbreak split across turns.
  • Images are recorded as not inspected.
  • Hallucination is not checked on gateway traffic, because the gateway does not receive the source documents.

If the judge does not answer, the rule-based and Comprehend findings still apply and the inspection counts as not finished, so it follows If inspection cannot finish.

If inspection cannot finish

Inspection does not finish when it runs past the time limit, when a detector fails or is temporarily switched off by the gateway after repeated failures, when the detection service is not available, or when a request has no text to inspect. Choose what happens under If inspection cannot finish:

SettingBehaviour
Forward the request (default)The request or response goes through uninspected, and the trace records fail_open: and the reason
Refuse the requestThe caller receives 503 guardrail_unavailable and nothing uninspected is forwarded. In a stream that has started, the stream ends with an error event.

Time limit for inspection is 1,500 ms by default and can be set from 100 to 10,000 ms. It covers looking up the policy and the inspection itself. Detector calls still running at the limit are cancelled.

An inspection that did not finish is never treated as a pass and never cached, so a client that retries straight away is inspected again. If Ethics & Bias detection does not finish but another category's result is a Block, the Block still applies.

Rule-based detectors. Secrets & Credentials, Source Code and the card number and SSN checks run inside the gateway and do not depend on the detection service, so their findings apply even when the service times out, fails or is not deployed:

  • A rule-based Block always blocks, under either setting.
  • With Refuse the request, any other outcome of an inspection that did not finish is refused with 503 as before.
  • With Forward the request, the rule-based result applies and the trace records both, for example redacted+fail_open:timeout.

The rule-based detectors have their own small budget per inspection: by default 50 ms and the first 1 MiB of text. A scan that hits it is incomplete. A rule-based category set to Redact then blocks instead of forwarding partly masked text, and with Refuse the request the inspection is refused unless something already blocked it.

Without the detection service

When the detection service is not deployed for the gateway, the gateway still looks up the policy and runs the rule-based detectors. A rule-based Block blocks. Other rule-based findings follow the failure setting as above, recorded with not_deployed. A request with no rule-based finding is recorded as not_deployed and follows the failure setting. Custom detectors, the other detection categories and the tool call check do not run.

Reason recordedMeaning
timeoutThe time limit was reached
incompleteOne or more detectors the policy uses returned no result, or the rule-based detectors hit their time or size limit
errorSomething outside the detectors stopped the inspection
not_deployedThe detection service is not available to the gateway. Only the rule-based detectors ran.
no_contentThe request has no text to inspect, for example images only. With Refuse the request the 503 message says so.
scan_backlog, buffer_overflowA streamed response outran the detectors or the hold limit, see Streamed responses

When a Warn or Redact result is combined with a detector that did not finish under Forward the request, both are recorded, for example warned+fail_open:incomplete.

What the caller sees

ResultNon-streamed callStreamed call
Request blocked400 guardrail_blocked400 guardrail_blocked, before any stream starts
Response blocked400 guardrail_response_blockedError event with guardrail_response_blocked, then [DONE]. In Hold until scanned, a plain 400 if the headers have not been sent yet.
Inspection could not finish under Refuse the request503 guardrail_unavailable503 before the stream starts, or an error event with guardrail_unavailable once it has
Warnx-ants-guardrail-warning headerThe header for request warnings; response warnings in an SSE comment just before [DONE]
n above 1400 guardrail_unsupported_requestSame

Errors use the OpenAI error envelope, so OpenAI SDKs raise their usual exception. The message is the policy's Blocked Response Message when it has one:

json
{ "error": { "message": "This request was blocked by the organization's AI guardrail policy.", "type": "invalid_request_error", "param": null, "code": "guardrail_blocked" } }

A streamed response that is stopped ends like this:

text
data: {"error":{"message":"The model's response was blocked by the organization's AI guardrail policy.","type":"invalid_request_error","param":null,"code":"guardrail_response_blocked"}} data: [DONE]

The warning header and comment carry category names only, never content. Categories are pii, pci, phi, ethicsBias, safety, secrets and sourceCode:

http
x-ants-guardrail-warning: pii,safety
text
: x-ants-guardrail-warning: pii data: [DONE]

OpenAI SDKs ignore SSE comments; a custom client can read them. All codes are in the API Reference.

Turn on inspection

Turn on AI Guardrails for the organization

In Organization Settings → Features → Feature visibility, turn on AI Guardrails. This needs tenantSecurity.features:admin.

Create or review the policy

In Governance → AI Guardrails, make sure each agent whose keys you want inspected has a policy with Real-time Enforcement on, with the categories and actions you want. If some keys are not bound to an agent, create a policy to use for them.

Configure the project

In Project Settings → Budget AI → AI Guardrails:

  • turn on Inspect content with AI Guardrails;
  • choose the Policy for keys without an agent, or leave it at None;
  • choose what happens If inspection cannot finish, and the Time limit for inspection;
  • choose how Streamed responses are handled.

Select Save AI Guardrails. This needs gatewayAi.settings:admin.

Override individual keys where needed

On Budget AI → Keys, open a key's row menu and select AI Guardrails. Choose Use the project setting, Always inspect or Never inspect. Use Always inspect to inspect some keys while the project switch is off, or Never inspect to exempt a key. The AI Guardrails column shows each key's mode. This also needs gatewayAi.settings:admin, so someone who can only issue keys cannot exempt one.

Check a request

Send a request with a test value your policy detects, then open the trace in Tracing and check gateway.guardrail.input in its metadata, and the entry in AI Violations.

A saved change reaches every gateway replica within about a second. If the save message reads "Saved, but not yet in force", it applies within 60 seconds.

Step-up verification and audit

Changes that weaken inspection ask for step-up verification:

  • turning Inspect content with AI Guardrails off;
  • changing If inspection cannot finish from Refuse the request to Forward the request;
  • setting a key to Never inspect.

Turning inspection on, choosing Refuse the request and the other settings are not challenged.

Every change is written to the audit log with before and after values. Changes that weaken or strengthen inspection get their own actions so you can alert on them:

ChangeAudit action
Project switch on or offsetGuardrailsEnabled, setGuardrailsDisabled
Failure settingsetGuardrailFailOpen, setGuardrailFailClosed
Policy for keys without an agent, including NonesetGuardrailDefaultPolicy
Key modesetKeyGuardrailEnabled, setKeyGuardrailDisabled, setKeyGuardrailInherited
Time limit or streaming modeupdate

Records

  • AI Violations. Every detection, including undeclared tool calls, is recorded in AI Violations with the key's id and alias. A value seen in two overlapping pieces of a stream is recorded once.
  • SIEM and webhooks. Blocks reach SIEM push and policy violation webhooks the same way as SDK and Portkey blocks. Secrets & Credentials and custom detector findings are sent even when the request was not blocked; see Severity.
  • Traces. Every inspected request's trace carries gateway.guardrail.input and gateway.guardrail.output, for example passed, audit_only, warned:pii, redacted, blocked, tool_not_allowed, tool_audit_only, approval_required, no_policy, fail_open:timeout or fail_closed:not_deployed. Content forwarded uninspected under Forward the request is recorded here with the reason.
  • Stored content. A blocked request is not stored on the trace, and a blocked response is not stored as output. A redacted request or response is stored masked.
  • Metrics. The gateway's /metrics counts outcomes by direction.

Latency

  • With a healthy detection service, inspection adds the time the detectors take plus a small gateway overhead, in the order of 20 to 30 ms per call in ANTS's own tests. Longer text takes the detectors longer.
  • The time limit caps the added time. A stalled detection service costs at most the time limit, after which the request is forwarded or refused as configured.
  • Scan while streaming keeps the time to first token about the same. Hold until scanned adds the whole generation time to the first token, by design.
  • Because earlier clean turns are remembered, long conversations stay close to the cost of a short one.
  • Ethics & Bias detection runs within the same time limit. If it often does not finish in time, raise the limit or expect it to follow the failure setting.

Turn inspection on for the keys that carry the traffic you need to inspect, and watch gateway.guardrail.* on traces for fail_open:timeout to tune the time limit.

Troubleshooting

SymptomLikely causeWhat to do
No AI Guardrails card in Budget AI settingsThe card is hidden in the current release (see the note at the top of this page)None needed: the settings already saved still apply
Policy for keys without an agent lists nothingNo policy has Real-time Enforcement on, or you lack AI Guardrails read accessTurn on Real-time Enforcement for a policy, or ask for read access
Traces show no_policyThe key's agent has no Real-time Enforcement policy and the project has no policy for keys without an agentCreate the agent's policy or choose a default policy
Traces show fail_open:not_deployed, or every call gets 503 guardrail_unavailableThe detection service is not available to the gatewayAsk your ANTS administrator to turn on AI Guardrails scanning for Budget AI
Frequent fail_open:timeout or 503 guardrail_unavailableThe time limit is too short for your traffic, or the detection service is overloadedRaise Time limit for inspection, or ask your administrator to check the detection service
400 guardrail_unsupported_requestThe request sets n above 1Send n: 1 or leave it out
Streams end early with guardrail_response_blocked though the policy redactsSent text cannot be masked in Scan while streamingUse Hold until scanned for keys that need redacted streams

Budget AI in front of Portkey

If your agents already call models through Portkey, you can place Budget AI in front of it: add Portkey as an upstream credential. Agents then hold Budget AI keys, so inspection, budgets, key expiry and key blocking take effect before traffic reaches Portkey. If the Portkey connector also inspects the same traffic, turn one of the two off to avoid inspecting it twice.

To keep Portkey as your only gateway instead, use the Portkey connector, which runs the same checks as a Portkey guardrail.

© 2026 ANTS Platform, Inc.Docs v1.0 · Last updated June 2026