How to Write AI Agent Guardrails That Fail Closed
How to write AI agent guardrails that fail closed, so a rule still denies the action when the check itself fails.

How to write AI agent guardrails that fail closed starts with the action, not the tool. Grants decide which tools an agent can see. Guard rules decide which actions are acceptable, even with a granted tool. RBAC vs ABAC for AI agents walks through that split. "Nobody deletes reports from the Q3 folder" is a guard rule. So is "never send customer data to external email addresses".
Write the rule a reviewer would write
Good rules are short, specific and testable. Name the action, the resource and the condition:
- Good: "Deny deleting any file under
/reports/q3." - Too vague: "Be careful with reports."
Each rule is compiled into a classifier prompt and evaluated before the call is forwarded upstream. How to secure an MCP server is that check on the server that receives the call. The classifier sees the tool, the arguments and the member, never the secret values used to execute it.
Monitor, then enforce
Start a new rule in monitor mode. Matching actions are allowed but flagged in the audit log, so you can check for false positives against real traffic. When the rule behaves, switch it to enforce.
How to write AI agent guardrails that fail closed
An enforcing guard must never fail open. If the classifier is unavailable or returns something unexpected, the action is denied and the denial is logged with the reason. A short outage costs you a retry; a silent bypass costs you an incident.
Pair rules with approvals
Some actions are fine sometimes. For those, require an approval instead of a hard deny. The request goes to the right reviewers, and nobody can approve their own request.
Related articles
Should AI Agents Have Their Own Identity or Act On Behalf of the User?
Should AI agents have their own identity or act on behalf of the user: delegate a live session, give unattended work its own identity, and put both names on the call.
Admin RBAC vs Agent Permissions: What Your MCP Gateway Actually Controls
The difference between admin RBAC and agent action permissions: console roles configure the gateway, and action permissions decide which tools a person's agent may call.
How to Stop MCP Token Passthrough and Confused Deputy Attacks
How to stop MCP token passthrough and confused deputy attacks: accept only a token issued for this server, and call upstream with a separate credential.
