Deny by Default: Policy-as-Code Guardrails for Agents That Act
Learn how to secure enterprise AI agents with deterministic policy gates, deny-by-default rules, human approvals, and audit logs.
There is a line in enterprise AI that nobody draws carefully enough: the line between an agent that answers and an agent that acts.
A chatbot quoting a stale wiki page is embarrassing. An agent issuing a refund, rotating a credential, or deleting a queue because its plan said so is an incident with a dollar figure and a postmortem. The difference is not how smart the model is. It is whether anything stands between the model's plan and the real world.
Most teams put nothing there except a system prompt that says, roughly, “be careful.” That is not a guardrail. That is a wish.
Prompts Are Not Policies
System prompts fail as enforcement for a reason that has nothing to do with model quality: they are instructions in the same channel as everything else the model reads. Retrieved documents, tool outputs, pasted user text — all of it flows into the same context window. A sufficiently clever injected instruction can override, reinterpret, or quietly work around your carefully written constraints. This is not a hypothetical; it is the entire premise of prompt injection.
Even without an attacker, prompts degrade as constraints. Models approximate. They summarize your rules back to you in ways that are almost right. They handle edge cases you never specified by improvising. A policy that lives in natural language, interpreted probabilistically, is not a policy. It is a suggestion with good intentions.
If you would not enforce an API rate limit by asking callers politely to go slow, do not enforce agent behavior by asking the model to be careful.
Put the Gate Between Plan and Action
The fix is structural: separate planning from acting, and put a deterministic enforcement point between them. The model proposes. The gate disposes.
The pattern looks like this:
def act(agent, plan, policy):
for action in plan.steps:
verdict = policy.evaluate(action) # deterministic: no model involved
if verdict.decision == "deny":
return escalate(action, verdict.reason)
if verdict.decision == "needs_approval":
return request_approval(action, verdict)
return agent.execute(plan.steps) # reached only if every step cleared
Three properties matter here:
- The evaluator is code, not the model.
policy.evaluateis a pure function over structured action descriptions. It does not reason, interpret, or improvise. Same action, same verdict, every time. That determinism is the whole point; you cannot audit a coin flip. - Actions are described before they execute. The agent must produce a structured plan (action name, target, parameters) that the gate can inspect. An agent that calls tools directly from generated text with no intermediate representation cannot be gated. The plan is the contract.
- Denial is the default. Anything not explicitly permitted is denied. This feels harsh until you remember what the alternative is: a permission model where new tool capabilities are allowed until someone notices they shouldn't be.
What a Policy Actually Contains
Policy-as-code is not one thing. In practice, it is three layers, and teams that skip a layer find out which one the hard way.
Action schemas. Every tool the agent can touch gets a machine-readable contract: which parameters it takes, what types they are, what values are legal. A refund action might allow amounts up to a threshold and require an order ID that exists in the system of record. Schema validation catches an entire class of failures before policy logic even runs: malformed, out-of-range, or nonsensical parameters never reach the rule engine.
Authorization rules. Who, or what, is this action allowed for? This is the least-privilege layer. A support agent can read account history but cannot issue refunds above a threshold. A deployment agent can roll back but cannot promote. These rules encode the org's actual authority structure, which means they change when the org changes, which means they live in versioned code with reviews, not in a wiki page or a Slack thread.
Escalation paths. Not every risky action should be a hard no. Some should be a pause. Irreversible actions (deletes, external sends, money movement above a threshold) route to a human approval queue with full context: what the agent wants to do, why it thinks it should, and what the policy said. The approval UI is a product surface worth investing in, because a guardrail that only ever says no gets bypassed, while one that says “not without a human” gets used.
Deny by Default, and What It Costs
Deny-by-default has a price, and you should budget for it honestly: legitimate actions get blocked while policies catch up to reality. The first week of a strict gate is a stream of escalations for things the policy authors did not anticipate. This is normal. It is also the mechanism by which the policy gets correct.
The mistake is treating every denial as a bug to be fixed by loosening the rule. Most denials are the system working. The productive response is a fast, visible loop: denied action, human review, rule update, deploy. Policy changes go through the same CI pipeline as everything else, with tests that assert the denial cases still deny. A policy without regression tests is a policy that decays.
There is a second cost, subtler: policy sprawl. Rules accumulate exceptions, thresholds drift, and after a year nobody can explain why refunds above a certain amount need two approvals. Treat policy code like any other code. Review it. Refactor it. Delete rules whose original incident nobody remembers. The gate is infrastructure; maintain it like infrastructure.
Failure Modes to Design For
Runtime guardrails do not eliminate risk. They move it into places you can see. Expect these:
The gate becomes a bottleneck. If every action needs policy evaluation and your evaluator is slow or your approval queue is unstaffed, the agent's latency becomes the guardrail's latency. Keep evaluation fast and local; reserve the slow path (human approval) for the genuinely irreversible.
Policy bypass through plan decomposition. A clever plan can split one dangerous action into several individually-permitted ones. This is the classic confused-deputy problem wearing an agent costume. The defense is evaluating the plan as a whole, not just step by step: the gate should see the full sequence and its cumulative effect before the first step executes.
Stale authority data. A rule that says “team leads may approve refunds” is only as good as the directory it checks. If the HR system says someone is still a team lead three months after their transfer, your gate enforces a fiction. Bind policy data to systems of record and treat stale lookups as a failure of the guardrail, not of the model.
Silent policy drift. Someone relaxes a threshold during an incident at 2 AM and forgets to revert it. Every policy change should be a commit with an author, a reason, and an expiry for emergency overrides. Temporary exceptions that outlive their incident are how guardrails become decoration.
Audit Is the Other Half
A guardrail that blocks bad actions but cannot prove it is half a system. Every evaluation should produce an immutable record: the action proposed, the policy version that judged it, the verdict, and the reasoning trace the agent gave. This log is what turns “the AI did it” into an accountable event. It is also the dataset that makes the policy better over time: aggregate denials tell you which rules fire too often, which escalations humans always approve (the rule is too strict), and which they always deny (the agent keeps trying something it should not).
Regulated industries already require this shape of evidence. Everyone else should build it anyway, because the first time an agent's action ends up in front of your security team, “we told it to be careful” is not an answer.
The Takeaway
Agents that act are not chatbots with extra steps. They are software systems with probabilistic planners and deterministic effects, and they need the enforcement architecture that combination demands: structured plans, deterministic gates, deny-by-default policies in versioned code, human escalation for the irreversible, and audit logs that prove it all happened.
The model proposes. The policy disposes. Build the gate before the agent touches anything real.
Views expressed here are my own and do not represent my employer.
Opinions expressed by DZone contributors are their own.