Inference Guardrails
Not to be confused with Agent Guardrails, which checks what a coding agent does to a repository. This page is about inference time: what a model is asked, and what it answers.
A guardrail is a request-level check Otari runs on the input before the provider is ever called. The caller opts in per request via a top-level guardrails field (a sibling of tools, not an entry inside it), and the model can't see or decline it.
Guardrails work on /api/v1/chat/completions, /api/v1/messages, and /api/v1/responses.
Bring up the guardrails service
docker compose --profile guardrails upThis starts the anyguardrails container (which wraps any-guardrail) and the encoderfile container that backs the default prompt-injection profile.
Against a gateway you run from source
To run only the service and point a gateway outside Docker at it, start the two containers on their own:
docker compose --profile guardrails up -d anyguardrails encoderfileThe service then listens on http://localhost:8183, with one profile, prompt-injection. The default encoderfile image is the arm64 build; on an x86 host, set OTARI_ENCODERFILE_IMAGE to the .x86_64-linux-gnu tag, as demo/guardrails/start.sh does. OTARI_ANYGUARDRAILS_IMAGE overrides the service image, so check that it names an image you have if the pull is refused.
Start the gateway with OTARI_GUARDRAILS_URL=http://localhost:8183. Stop the containers with docker compose --profile guardrails down.
What a guardrails service answers
Any service that speaks this contract works, not only the bundled one:
POST /validate {"profile": "...", "input_text": "...", "validate_kwargs": {...}}
→ {"profile": "...", "result": {"valid": false, "explanation": null, "score": 0.997}}valid: false means the input was flagged, and valid: null is an inconclusive verdict. GET /profiles is optional: it lists [{"name": "prompt-injection", "guardrail_name": "injec_guard"}] so the dashboard can offer the profile in a picker. Check the service directly with:
Using a guardrail
Add a guardrails field to your request:
Modes
monitor (default)
Forwards to the provider and surfaces the verdict on the Otari-Guardrails response header.
block
Returns 403 and never calls the provider when the input is flagged.
Reading the Otari-Guardrails header
A served non-streaming request carries one entry per input guardrail. A streamed response does not carry the header yet, though a block guardrail still refuses the request before any bytes are sent.
valid: null alone cannot tell a check that did not run from one that ran and gave no verdict, so status says which:
status
Meaning
evaluated
The check ran. valid is true or false.
inconclusive
The check ran and the guardrail returned no verdict.
unavailable
The check could not run, and the request was served anyway. reason says why.
reason appears only on an unavailable entry. not_configured means the deployment has no guardrails service for the profile. evaluation_failed covers everything else: the service is down, does not serve the profile, or answered something malformed. The detail goes to the gateway's log, not to the caller. The guardrail's own explanation stays out of the header too, because it is free text of any length.
When the guardrails service is unreachable
A block guardrail that cannot be evaluated at all (service down, no URL configured, malformed response) fails closed: the request is rejected with a 502 rather than forwarded unchecked. A monitor guardrail fails open, since it was never enforcing.
A mandated entry whose endpoint fails its safety check counts as unevaluable too, and takes the same two paths. That covers a host that has stopped resolving, so an organization's endpoint going away is an outage of that entry rather than a refusal of every request scoped to it. A url you send in the request body is different: it is yours to fix, so a URL that fails the check is a 400 naming what was wrong with it.
Set "on_unavailable": "monitor" on an entry to trade that enforcement for availability: the request is served and the check is recorded as unavailable. "on_unavailable": "block" is the default and the pre-existing behavior. An operator can also mandate a guardrail on a routing policy, in which case the stricter of the operator's and the caller's settings applies and a caller cannot weaken the mandate.
Organization guardrails
Everything above is one caller opting one request in. An organization can also mandate a guardrail, so that it runs on every request from the workspaces it chooses whether the caller asked for it or not. The two layers compose; they do not replace each other, and an organization that configures nothing leaves every request checked exactly as it was.
In the dashboard this is Organization, then Guardrails: one table of the guardrails the organization has configured, and one of where each runs. It says there when a guardrail is not running, and whether the requests it covers are being refused or served unchecked.
Entries are managed over /api/v1/organizations/me/guardrails (master key, and an organization owner or admin), and each one carries:
profile
The profile on the guardrails service. One entry per profile per organization.
mode, on_unavailable
The same two settings a request-body entry has, with the same meanings.
url
An endpoint of the organization's own. Omit it to use the deployment's guardrails_url.
definition_id
One of the organization's own guardrail definitions, for Otari to build and run the check itself. Exclusive with url and credential, which name a service instead. An explicit null clears it.
credential
Sent to that endpoint as Authorization: Bearer. Requires url, which must then be https, so the credential is never sent to the deployment URL, which may be a plain-http sidecar. Encrypted at rest, never returned.
validate_kwargs
Forwarded to the guardrails service /validate call. A parameter whose name looks credential-shaped (it contains key, secret, token, password, authorization or credential) is read back as *** rather than its stored value. Sending *** back keeps what is stored, so editing the rest of an entry does not overwrite the parameter you were never shown.
enabled
false stops this mandate everywhere without discarding the entry.
applies_to_all_workspaces
true runs it in every workspace, including any created later.
workspace_ids
The workspaces it runs in, when it does not apply to all of them.
Testing a mandate
A mandate that runs on a guardrails service has a Test action on its row. It sends some text to the service the mandate names, with its endpoint, credential and validate_kwargs, and shows the verdict. Nothing is stored. The same call over the API:
It answers {"valid": false, "explanation": null, "score": 0.997}. A test always reports a failure rather than serving the text unchecked, whatever the mandate's mode, and works on a mandate with enabled: false. A service that cannot be reached answers 502, with the reason in the gateway's log. A mandate with no endpoint on a deployment with no guardrails_url answers 409, and so does one that runs a definition: test that one from the definition's own row.
Which profiles exist, and what they take
GET /api/v1/tool-settings/guardrails/profiles lists the profiles the deployment's guardrails service has actually built, with the validate_kwargs each one accepts. It is what the dashboard's guardrail form is driven by, so an entry is configured by picking a profile and filling in typed fields rather than by naming a profile from memory and hand-writing a dict.
Neither half of that answer is a list Otari keeps. The profiles come from the service's own GET /profiles, which reports each profile's name and the any-guardrail class it was built from; the parameters come from any-guardrail's parameter registry, keyed by that class. Only validate parameters appear: a guardrail's constructor arguments are fixed by the operator's service.yaml when the service boots, and POST /validate takes nothing else.
A service that is unconfigured, unreachable, or older than its /profiles endpoint answers "available": false with a reason rather than an error, and the dashboard falls back to naming a profile by hand. The same fallback covers an entry that points at an endpoint of its own: only guardrails_url is read here, because a URL taken from an entry would be one a caller chose.
Any API key and any signed-in user can read this list, because a profile name is what a caller puts in a request. Each gateway worker keeps the answer for 30 seconds, so many reads cause at most one request to the guardrails service in that time. A changed guardrails_url is read at once.
Which guardrails Otari can run itself
GET /api/v1/tool-settings/guardrails/catalog lists the guardrails Otari can build and call without a service in front of them, with the constructor and per-call arguments each one takes. It is the counterpart of the profiles read above: the same picker, for a guardrail this deployment configures rather than one an operator's service.yaml already built.
It is not every guardrail any-guardrail ships. A guardrail runs either as a call to a hosted API or by holding model weights in the process running it, and Otari does the first only. The second belongs in the guardrails service guardrails_url points at, which is what the /profiles half of this page describes, so the two catalogs divide on exactly that line. The rule is any-guardrail's own backend metadata rather than a list Otari keeps, and it reads the backend a guardrail defaults to. A guardrail that holds model weights and also offers a hosted API is not listed: that second path is chosen by an argument of any-guardrail's own factory, not by one of the guardrail's parameters, so a saved configuration has no field in which to ask for it and Otari would load the weights instead.
The catalog reaches no service, so unlike the profiles read it has no unavailable state. A tenant reads it too: the form that defines a guardrail belongs to an organization, and an owner or admin fills it without operator standing, so any signed-in user reaches this read and so does any API key. What it answers is a property of the installed library, identical on every deployment of the same build, and a parameter's environment variable is named without saying whether it is set.
Defining a guardrail on an organization
The catalog above is a picker, and /api/v1/organizations/me/guardrail-definitions is where what it picks is saved. A definition names one of the catalog's guardrails and the arguments to build it with, so an organization can define a check rather than only name a profile some service already serves. Master key, and an organization owner or admin, the same audience as the mandates.
name
The organization's own label. One definition per name per organization.
guardrail_name
The guardrail to build, as the catalog names it.
create_kwargs
The constructor arguments. Both halves of the form go here, and the catalog's own secret flag decides which of them are credentials.
enabled
false stops the guardrail everywhere it is mandated, in one write, without losing the arguments it took to set up.
A read gives the plain arguments back as they were stored and each credential as its name alone:
create_kwargs comes back in clear deliberately: the credentials were already taken out of it by flag, and a form has to round-trip an endpoint or a project id. Sending a *** back keeps the value stored under that name, a new value rotates it, and a credential left out of a sent map is cleared, so editing the endpoint of an entry does not overwrite the key you were never shown. Omitting create_kwargs altogether leaves both columns untouched and reads neither, which is what lets an admin on a deployment whose OTARI_SECRET_KEY has moved still turn the guardrail off and repair it by typing the credential again. Such a row reports secrets_decryptable: false and an empty create_secrets rather than failing the whole listing.
What may be defined is the catalog's answer and not a list Otari keeps, so the set the form offers and the set the store accepts cannot disagree. A definition is refused when its guardrail is not one this deployment can build, when an argument is not one that guardrail declares, when an argument is a live object rather than configuration (Bedrock's boto3_session and watsonx's api_client are the two, and the message names the arguments to use instead), and when a required argument that no environment variable can supply is missing. Whether a variable is set is never consulted: the process that writes the row is not always the process that builds the guardrail, and the row may outlive both.
An argument whose value carries a scheme is checked as an address too, because a later step builds the guardrail from these arguments and dials it. Seven of the eight definable guardrails take one, spelled endpoint, base_url or url, and the check reads the value rather than the argument's name, so a spelling any-guardrail adds next is covered without an Otari release. It refuses plain http, an address with no host, and a host that resolves inside the network Otari runs in, and it looks inside a nested argument such as Alinia's detection_config. The check runs at the write and not on every request: the guardrail owns the socket it dials, so a later lookup would report something Otari could not act on. Two things follow. An endpoint that arrives from an environment variable (ALINIA_ENDPOINT, CONTENT_SAFETY_ENDPOINT, WATSONX_URL) is never checked, the same carve-out the required-argument rule makes, and that address is the operator's own rather than an organization admin's. And an operator who has set OTARI_MCP_ALLOW_PRIVATE_HOSTS=true has turned the private-address half of this check off as well: one flag covers every address this gateway is asked to dial.
Two guardrails the catalog lists cannot be defined this way. bedrock_guardrails needs both AWS keys, because without them boto3 falls back to the instance role of the host Otari runs on, which is the operator's identity rather than the organization's. And any_llm is refused outright: it takes no credential of its own, so it would judge text by calling an LLM on whatever key the deployment's environment holds, with nothing metering the call and nothing refunding it.
A mandate points at a definition with definition_id, and then names no url of its own: a check runs either on a service the organization named or on the guardrail Otari builds from the definition, never on both.
A definition's name is not a mandate's profile. The name is what an organization recognizes a definition by, so the same guardrail can be defined twice under two names with different arguments; the profile is what a caller sends, and what the layer merge keys on.
What Otari builds from a definition
Otari builds every enabled definition when it starts. A built guardrail is a vendor client held in memory by each worker, so a request that needs one never waits for a vendor handshake and never builds anything itself.
A definition it does not hold is one that is disabled, one that was deleted, or one that would not build. Nothing is built lazily: a request cannot tell those three apart, and building while a request waits is what holding them ready avoids.
A write rebuilds the definition it wrote, on the worker that served it, and answers with the outcome. The row is saved first and built second, so a guardrail this deployment cannot construct is still stored: losing the arguments an admin just typed would be the worse failure, and the response says what happened instead. Turning a definition off stops it on that worker in the same write rather than up to thirty seconds later.
Every other worker catches up on its own clock. Each re-reads the definitions about every thirty seconds and rebuilds only the rows that changed, so a guardrail whose arguments nobody touched is not rebuilt, and a write made on one worker reaches the rest within that window.
A build can fail, and a failed build is kept rather than retried. A wrong credential, an endpoint the vendor rejects, or a OTARI_SECRET_KEY that can no longer read the stored secrets all end the same way: the definition is held as failed until its row changes. Trying again could not help, and a check that quietly stopped being evaluated is worse than one reported as broken. A build that merely ran out of time is the exception and is tried again, because nothing was learned about the definition either way.
The reason a build failed goes to the gateway's log and names the guardrail class, the definition's id and the type of error, and nothing else. A vendor library may put the arguments it was handed into its own error message, and those arguments are the organization's credentials, so that message is never logged, and it is never in an API response either.
One case an operator can fix, and the only one whose message is logged in full: a vendor SDK that is not installed. Otari depends on the SDK of every guardrail the catalog lists, so this happens only on an install that left them out, such as a plain pip install that skipped any-guardrail's extras. A definition then saves and fails to build, with an ImportError naming the extra to install.
Telling whether a definition is running
A read of a definition carries build_state:
built
The guardrail is constructed from the arguments you are looking at, and mandates pointing at it are being evaluated.
failed
This exact version was tried and would not build. Every mandate pointing at it is unevaluable, which with the default on_unavailable: block means those requests are refused.
pending
Nothing is held for this version yet. Normal right after a write on a worker that did not serve it, and normal for a few seconds if the build is still running.
disabled
enabled is false, so nothing is built on purpose.
It answers for the worker that served your request. There is no deployment-wide answer here: with several workers or replicas, a read taken seconds after a write can say pending on one and built on the next, and both are true. Treat a lasting pending as worth a second look rather than as a failure, and failed as the one to act on.
This is the field that keeps enabled: true honest. Without it a definition with a mistyped credential saves, reports nothing wrong, and refuses every request in the scope of any mandate that names it.
What a request does with one
A mandate that names a definition is checked by the guardrail this worker holds, in this process. Nothing about the check leaves the gateway: no request to the guardrails service, and no second network hop beyond the one the vendor client makes itself. A mandate that names a url instead is posted to that service exactly as before, and a deployment that mandates neither is untouched.
Everything a verdict does is the same either way. A flagged check in block mode answers 403 guardrail_violation; in monitor mode the request is served and the verdict travels back in the Otari-Guardrails header. The mandate's validate_kwargs reach the guardrail as they reach the service, so one policy field means one thing.
A definition this worker does not hold makes the check unevaluable, and mode and on_unavailable decide from there: block with on_unavailable: block refuses the request with a 502, and anything else serves it and records the check as unavailable with the reason evaluation_failed. That covers a definition that is disabled, one that was deleted, one that failed to build, and the thirty second window after a write in which a sibling worker has not caught up. The request is never quietly sent to the deployment's guardrails service instead, which has never heard of that profile.
The caller is told the profile and nothing else. The definition's id, the vendor's own words and the reason a build failed all stay in the gateway's log, for the same reason a remote endpoint stays out of a 502 body: none of it is the caller's to see or to fix.
One case where a definition stops serving a profile: a routing policy that mandates the same profile with a url. The operator's layer is the outermost one, so it owns where that check is sent, and the organization's definition steps aside.
Turning one off
Two switches, stopping different amounts of work. enabled: false on a definition stops the guardrail everywhere it is mandated, in one write, and keeps the arguments and credentials it took to set up. enabled: false on a mandate stops that one mandate, and leaves any other mandate on the same definition running.
A disabled definition is dropped immediately on the worker that served the write, and on every other worker at its next read, so nothing keeps its vendor client alive. It then reads as build_state: "disabled", and a mandate still pointing at it becomes unevaluable: mode and on_unavailable decide what happens to the request, the same as an endpoint that cannot be reached.
Deleting a definition a mandate still names is refused rather than cascaded, because dropping it would silently stop a guardrail running. The refusal names the profiles holding it, and enabled: false is the answer when switching it off was the point.
How the layers compose
Three layers can name a guardrail: the caller's request, the caller's organization, and a routing policy the operator wrote. They are merged by profile, and each layer may add a check or tighten one but never weaken what another asked for: block beats monitor for both mode and on_unavailable. So a caller who sends "mode": "monitor" for a profile their organization mandates in block mode still gets block.
Where two layers name one profile, the outer layer owns the endpoint the check is sent to, so a caller cannot point a mandated check at a service of their choosing. The operator's routing policy is the outermost of the three; an organization's entry loses its credential where a policy has taken over the profile, because that credential was stored for the endpoint the organization named.
A new workspace inherits the entries marked applies_to_all_workspaces and nothing else. A workspace cannot opt out of an entry scoped to it: the scope is the organization's to set.
Runnable walkthrough
A full end-to-end demo is in demo/guardrails/.
Last updated
Was this helpful?
