LLM guardrails
Screen every message into and out of your LLM app with one batched yes-no call.
An LLM app needs a gate on both sides. You check the user message before you spend tokens. You check the model reply before a person reads it.
yes-no runs that gate. You send the message once and a list of statements.
Each statement returns its own probability. One call covers the whole policy.
The input gate
Send the user message as text and your policy as statements. The five below cover
jailbreak, harmful requests, self-harm, medical advice and urgency.
The response keeps the statement order you sent.
The whole gate costs one call. Extra statements add no inference call; each adds only its own length to the billed input, at $0.04 per million input tokens and $0 per output token. See Pricing.
Latency stays flat too: yes-no with 2 statements took 1.12 s, and a single statement took 0.75 s to 1.25 s.
Write the statements as cases
The label text is what the model reads. A statement must describe the case, not the verdict.
when_true: "yes" and when_false: "no" carry no meaning, and they measurably break the answer.
One support message scored the statement The customer expresses urgency. at probability 1
with case wording. The same call with when_true: "yes" and when_false: "no" returned
answer: false at probability 0.004.
Never write hints as verdicts. Use when_true and when_false to describe the two situations,
or leave both out and let the statement stand alone.
Pick a threshold per rule
One threshold for the whole gate is wrong. The cost of a block differs per rule.
Urgency is a routing signal, not a guardrail. A polite password-reset message scored urgency at probability 1. The other four rules scored 0 on the same message.
The output gate
Screen the model reply with a second list. The reply is the text this time.
Hold the reply and send a safe message instead. Log the probabilities for review.
Operational notes
- Run the input gate before the LLM call. You save the tokens on every blocked message.
- Keep one policy list in code. Add rules to the list, not new calls.
- A
yes-nocall takes at most 32 statements. Split a larger policy across two calls. - Handle
overloaded(529) with backoff. Decide in advance whether a failed gate opens or closes. - Write policy statements in English, even when the user messages are not in English. Every measured probe used English statements against non-English text and scored correctly.
Next
- Thresholds and confidence routing sets the bands per action.
- Writing good statements and labels covers hint wording in full.
- Content moderation adds a harm scale on top of these flags.