Skip to content
Smartplane

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.

By Smartplane team

Back to blog

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.