How to set up guardrails for AI agents
AI guardrails are rules that check what enters and exits your agent. Set them up by identifying the risks that apply to your agent, running checks in monitor mode first, and switching to enforce once they're working.
By Arun Prasad · Published · Last updated
On this page
Why guardrails matter
An agent can fail without raising an error: a tool can return a 200 and the task can still fail. Standard monitoring shows the request went through, not whether the answer was right, safe or on-topic.
A guardrail is a rule that checks what the user sends in and what the agent sends back. It can flag the exchange or block it.
To set them up, identify the risks you need to cover, run the checks in monitor mode first to review triggers, then switch to enforce mode if the rule is working as intended.
The risks worth guarding against are well documented. The OWASP Top 10 for LLM Applications names prompt injection and sensitive information disclosure among its entries. These two map to checks you can run, plus one reliability risk:
- Prompt injection. Input that tries to override your agent's instructions. A prompt injection check looks for it before the request reaches the model.
- Personal data. Names, health details or identifiers in prompts or replies. A PII/PHI check looks for them.
- Off-topic replies. Not a security risk in OWASP's sense, but a reliability one. An off-topic check flags answers outside what your agent is meant to do.
The next five steps turn these risks into working rules.
Step 1: Decide which risks your agent needs guardrails for
Pick the few risks that apply to your agent instead of covering everything. Every extra rule is one more thing to tune and one more source of false alarms.
Start from what your agent can see and say:
- It handles user details or records. Cover personal data in prompts and replies.
- It accepts free text from the public. Cover prompt injection, using the OWASP risk categories as a checklist.
- It has a narrow job, such as billing support. Cover off-topic answers.
- Its output must follow a fixed shape, such as an order number format. Cover format rules.
Write each choice as one sentence: "This agent must never reveal X" or "This agent must only discuss Y." A rule you can't state in one sentence is usually too broad to check.
Step 2: Choose the type of check for each risk
For each risk, choose rule-based checks for patterns you can describe precisely, and use evaluators for cases where judgment matters.
A practical way to match them:
- Clear patterns (card numbers, ID formats, known attack phrases): use a rule.
- Meaning-dependent cases ("did this reply stay in scope?"): a rule can approximate it, and a model-based judge can score it more flexibly.
The two types answer different needs. A rule is predictable and easy to explain to a reviewer. A model-based judge covers more cases, but you have to check its verdicts.
In PRISM, guardrails are rule-based with no LLM involved. Model-based judging is a separate feature, Evaluators, which you can read about on the PRISM evaluators page. This guide covers guardrails only.
Step 3: Put the check where it can act
Make sure every route your agent takes to reach a model runs your guardrail checks. Otherwise, some paths will be unprotected.
This is where setups go wrong. If one route to your model bypasses the guardrail, that route is unprotected. List every path your agent uses to reach a model, and confirm each one is covered.
PRISM runs guardrails on verified runtime paths, in Monitor and Enforce modes. On the zero-code proxy, guardrails run inline, so blocked requests never reach the provider. The proxy is one path among several. Bedrock and Azure, for example, don't go through the proxy. Check which paths your integration uses before you assume a rule applies to them. For the full list of supported paths, see the PRISM integrations page.
Step 4: Run in monitor mode before you enforce
Start every rule in Monitor mode and let it run on real traffic before enforcing it. This shows you what the rule triggers without blocking users. A rule that blocks real users by mistake does more damage than the risk it was meant to stop.
PRISM has two modes, Monitor and Enforce, and records every trigger and override. A sensible routine:
- Turn on a rule in Monitor mode.
- Let it run on real traffic for long enough to see a range of requests.
- Read the recorded triggers. Mark each as a correct catch or a false positive.
- If nearly all are correct catches and the rule type can block, switch it to Enforce mode. If they aren't, keep it in Monitor mode, or rewrite it.
Move rules one at a time. That way, if something changes after the switch, you know which rule caused it.
Step 5: Review triggers and tune the rules
Look at the triggers your rule caught during the monitor phase, then loosen or tighten it based on what was correct and what wasn't.
Guardrails and evaluators solve different problems for agents. Guardrails intercept at request or response time; evaluators judge the quality of an outcome after the fact. You can read more about how evaluators work.
In practice:
- Read each trigger in the context of the whole run, not just the flagged message. A trace is the record of one run, with its inputs, outputs and steps. Context often shows whether a trigger was right.
- Loosen rules that fire on harmless traffic. Tighten rules that miss real problems.
- Use evaluators to catch what no guardrail rule covers, such as a reply that is on-topic and polite but wrong.
Every trigger and override is recorded, so you can look back at what a rule did.
How this looks in production
In PRISM, guardrails are available on the Builder plan and above. They run in Monitor or Enforce mode on verified runtime paths. PRISM Guardrails have ten rule types:
- PII / PHI Detection
- Prompt Injection
- Regex Pattern Match
- Off-Topic Detection
- Content Moderation
- Toxicity Detection
- Secrets Detection
- Code Safety Linter
- SQL Sanitizer
- Language Restriction
Every rule flags or blocks. Four of them can block today: PII/PHI Detection, Prompt Injection, Regex Pattern Match and Off-Topic Detection. The other six flag but do not block for now.
The checks are rule-based, and no LLM is involved. Every trigger and override is recorded. On the zero-code proxy, guardrails run inline, so blocked requests never reach the provider.
To use the proxy, set your client's base URL to https://api.prism.blockconvey.com/proxy/anthropic, /proxy/openai/v1 or /proxy/gemini, and send your PRISM key in the X-PRISMtrace-Key header from the same client config.
Example:
from anthropic import Anthropic
import os
# Example: point the Anthropic client at the PRISM proxy
client = Anthropic(
base_url="https://api.prism.blockconvey.com/proxy/anthropic",
default_headers={"X-PRISMtrace-Key": os.environ["PRISMTRACE_API_KEY"]},
)
# Your model key is passed through as normal.Some limits to know:
- On the zero-code proxy, blocked requests never reach the provider. Bedrock and Azure don't go through the proxy.
- Guardrails are not on the Free plan.
Common mistakes
- Enforcing before monitoring. A new rule that blocks traffic on day one will block some real users. Fix: start every rule in Monitor mode and read the recorded triggers before you enforce.
- Assuming guardrails replace evaluation. Guardrails check for specific risks. They don't tell you whether the agent did what the user wanted. Fix: pair them with evaluators that judge the outcome.
- Using one broad rule for every risk. A single catch-all rule is hard to tune, and you can't tell which risk it caught. Fix: write one rule per risk, each stated in one sentence.
- Never reviewing triggers. Traffic changes, and rules that fit last month can misfire this month. Fix: review recorded triggers on a schedule, and note each override.
- Assuming every path is covered. A rule only protects the paths it sees. Fix: list every route your agent takes to a model and check each one against your integrations. Remember that Bedrock and Azure don't go through the proxy.
When PRISM guardrails aren't the right fit
PRISM Guardrails have ten rule types and run as part of a hosted platform that records traces and sessions and runs evaluators. If you need validation written inside your own code, checks beyond those ten rule types, or a self-hosted setup, a different tool may suit you better.
Start with one rule in Monitor mode
Connect your agent, pick the risk that matters most, and read what the rule triggers before you enforce anything.
Paid plans from $20/month.