
To stop an agent before it acts on a bad answer, put a check between the model's decision and the tool call. Write that check as code, so the model cannot argue with it. The check compares the arguments with your systems of record and runs the call with the asking user's own permissions. Anything above a threshold goes to a named person. A wrong answer then becomes a refused call instead of a wrong refund, email or record change. AI guardrails are one control inside enterprise AI governance, next to approval gates and run logs.
In July 2025, SaaStr founder Jason Lemkin reported that Replit's coding agent deleted a production database. It did so during a code freeze he had declared in the conversation, as The Register reported on July 22. Replit's CEO, Amjad Masad, called it unacceptable. Replit responded by automatically separating development and production databases. The freeze was an instruction, and the agent went ahead anyway. The fix was a control outside the model.
AI guardrails are checks that run outside the model wherever an agent reads, writes or acts. They can stop, change or reroute whatever passes through. NVIDIA's NeMo Guardrails documentation names five kinds of rails (input, retrieval, dialog, execution and output). The OpenAI Agents SDK separates input, output and tool guardrails. Whatever the framework, an agent has five places worth checking.
| Checkpoint | What it checks | Example |
|---|---|---|
| Input | What the user sends, before the model sees it | A jailbreak attempt or a pasted API key |
| Tool result | What a tool or search returns, before it enters the context | An instruction hidden in a retrieved email |
| Output | What the model drafted, before anyone reads it | A figure or policy that is not in the sources |
| Pre-tool | The tool call and its arguments, before it runs | A refund larger than the order |
| Environment | What the agent's credentials can reach at all | A delete against production |
The first three catch bad text. Only the last two stop a bad answer before it changes a system, so most of this post is about them.
A system prompt is text the model weighs alongside everything else in its context. That context includes customer emails, retrieved documents and tool results that someone else wrote. A line saying "never issue refunds above 250" makes a bad refund less likely, and it cannot make one impossible. Lemkin's code freeze sat in the same conversation as the delete.
OWASP's Top 10 for LLM Applications 2025 calls this failure LLM06, excessive agency. It traces it to three causes: excessive functionality, excessive permissions and excessive autonomy. Every fix it recommends sits outside the model. Give the agent only the tools the job needs, and give each tool the narrowest permissions that work. Run tools in the user's own context and require approval for high-impact actions. Let the downstream system decide what is allowed, instead of asking the model. OWASP calls that last one complete mediation.
Prompt injection, where an attacker hides instructions in text the agent reads, makes this worse. The attacker never has to beat the system prompt, only compete with it. Our post on data governance for AI walks through EchoLeak, the Microsoft 365 Copilot flaw where one crafted email was enough. This post assumes the model will sometimes be wrong or manipulated, and asks where each wrong answer gets stopped.
Each checkpoint sees a different thing, so each bad answer has one place where it is cheapest to stop. Pick a scenario to see which check catches it and which checks it slips past first.
You catch text problems, such as an invented policy or an unfounded promise, by checking the draft against its sources. You catch action problems, such as a wrong amount, the wrong account or a destructive command, by checking the call against your systems. The model's confidence plays no part. IES Limited's daily MI alerting runs the text check in production. The model gets finished numbers from the database, and a verification step names any figure it was not given. Once, the model put two numbers into its narrative that were not in the input. The brief said so at the top and asked for verification before it went out.
The pre-tool check is the last point where you can stop a bad answer with nothing to undo. It runs as ordinary code between the model's tool request and the API that does the work. A complete check covers six things.
Change the tool, the amount and the asker to see how one call moves between running, waiting and blocked.
The approval step is cheap to build with today's tools. n8n's human-in-the-loop for tools pauses an AI Agent before a chosen tool runs. It sends the reviewer the tool name and the parameters the model filled in, through Slack, Microsoft Teams, Gmail, Outlook and other channels. Approve runs the tool with those inputs, and deny cancels it. Our builds run on self-hosted n8n inside your environment, so the gate, the log and the credentials stay there too.
By default, the OpenAI Agents SDK runs input guardrails at the same time as the agent. Its documentation warns that the agent may already have used tokens and run tools before a failed check cancels it. Its blocking mode and its tool guardrails run before the tool executes. For any agent that writes, the check has to finish before the call starts.
Some checks have a yes or no answer and belong in code. Others need judgment, so they need a model, usually a smaller one, or a second agent with its own instructions. Mix them up and you get either a fragile rule set or a check that can be talked round.
| Check type | Good for | Weak at | Example |
|---|---|---|---|
| Deterministic rule | Schemas, bounds, permissions, allowlists, thresholds | Anything phrased in an unexpected way | Refund total compared with the order |
| Classifier or model check | Tone, topic, injected instructions, unsupported claims | Exact values, and it can be wrong itself | n8n Guardrails node jailbreak check |
| Second agent | Policy and business rules applied to a full draft | Cost and latency on every turn | Pinkcube's Gatekeeper |
| Human approver | High-value, irreversible or unusual actions | Volume; people tire of approving | Refunds above your threshold |
n8n's Guardrails node shows the split inside one tool. Its keyword, URL, secret key, PII and custom regex checks match patterns. Its jailbreak, NSFW and topical alignment checks call a chat model you attach. Any violation sends the item down a fail branch. Use rules wherever a rule can decide, and save model checks for the judgments rules cannot make. Our AI governance tools comparison sets Bedrock Guardrails, policy engines and tracing tools side by side.
A guardrail that crashes the run teaches users to work around the agent. A good response is only as big as the problem it found, and it tells the agent or the person why.
Pinkcube's chat agent is built on one more assumption: it will sometimes say it did something it never did. It has no permission to create tickets at all. A separate triage agent reads each finished conversation, treats every promise as something owed, and files the ticket the chat agent only said it filed (Pinkcube case study).
Test the guardrails the way an attacker or a confused customer would use the agent, and score every result. Before Pinkcube's agent met a customer, an evaluation workflow scored it on 76 hostile scenarios, from 1 to 5. The agent averaged 4.62, with 64 perfect scores. The twelve scenarios that fell short became hardcoded business rules. The worst one, a sizing question that came with two product links, now goes to a ticket by rule.
After launch, the run log shows which checks fire and how often, and that tells you which rule to add next. Our AI managed services keep that loop running after go-live. The enterprise AI governance page lists the controls that ship in every workflow. Some agents reach your systems through MCP, the Model Context Protocol that AI tools use to connect to company data. For those, MCP security covers gateways and approvals at that layer. For what to watch once the agent is live, see what monitoring an enterprise AI agent needs in production.
AI guardrails are checks that run outside the model and can stop, change or reroute what an AI system reads, writes or does. For agents, the most important ones sit before a tool call runs and in the permissions the agent's credentials carry. Those are the last points before a system changes.
A system prompt is an instruction the model weighs against everything else in its context, so untrusted text can outweigh it. A guardrail is code, or a separate check outside the model, that decides whether something passes. The model cannot override it, whatever it writes.
They are the same checks, applied to everything an agent handles: input, tool results, drafted output, tool calls and the environment. OWASP's LLM06 guidance adds checks specific to agents. Give the agent the fewest tools and the narrowest permissions, run tools in the user's own context, and require approval for high-impact actions.
A named person approves an action before it runs. The agent prepares the call with its arguments and context, the reviewer approves or denies it, and both the request and the decision are logged. Reserve it for high-value or irreversible actions so reviewers do not approve on autopilot.
Rule checks add only milliseconds. Model-based checks and second agents add one model call each. That is why they suit drafts a customer will read, and are kept off simple reads. Approval gates add the reviewer's response time, so set the threshold where the risk justifies the wait.
Ovidius builds agents with these checks written into the workflow, tested against your own scenarios before launch. See our AI agent development services or book a discovery call to walk through the actions your first agent will take.