By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Your agent's system prompt says 'never refund more than $500.' A user submits a support request asking for $900, and the model approves it anyway. Prompts are instructions to the model, not guarantees. If you need rules that actually stick, you need policy enforcement outside the model itself.
A clever user—or a prompt-injected web page—can talk the model out of following your system prompt. The model sees conflicting instructions and makes a judgment call. Policy, by contrast, runs outside the model on every tool call. It's deterministic. It doesn't negotiate.
When your agent tries to call a tool, a policy engine intercepts the request. It checks three things: who is making the request (principal), what tool they're calling (action), and where they're calling it (resource). It can also inspect the request details—like the refund amount. Then it says ALLOW or DENY.
Cedar is AWS's open-source policy language and a CNCF project. A Cedar policy is a single statement: permit or forbid. It names the WHO (principal), WHAT (action—a tool), and WHERE (resource—the gateway). You can add conditions to inspect request context.
// Allow refunds, but only below $1000
permit(
principal is AgentCore::OAuthUser,
action == AgentCore::Action::"RefundTool__process_refund",
resource == AgentCore::Gateway::"<gateway-arn>"
)
when { context.input.amount < 1000 };
// Only managers may change coverage
forbid(
principal is AgentCore::OAuthUser,
action == AgentCore::Action::"InsuranceAPI__update_coverage",
resource == AgentCore::Gateway::"<gateway-arn>"
)
unless { principal.hasTag("role") && principal.getTag("role") == "manager" };
The first policy permits refunds under $1000. The second forbids changing insurance coverage unless the caller has a 'manager' role tag. Both are simple, readable, and enforced outside the model.
One critical detail: the action names and how tool names appear in Cedar come from your gateway targets. Don't guess. Generate or inspect them in the console or CLI.
First: DEFAULT DENY. If no policy matches a request, the answer is DENY. You must write a permit policy for anything you want to allow.
Second: FORBID WINS. If any forbid policy matches, the answer is DENY even if a permit also matches. Forbid always takes precedence.
You can write Cedar directly if you know the syntax. Or you can describe the rule in plain English and let AgentCore generate Cedar for you.
agentcore add policy-engine --name RefundPolicyEngine
agentcore add policy --engine RefundPolicyEngine --generate "Allow refunds under 1000 dollars"
# flags may differ by CLI version: run agentcore add policy --help
The second approach is faster, but it comes with a non-negotiable rule: always read the generated Cedar before enabling it. A policy you do not understand is a policy you do not control.
Always read generated Cedar before enabling it. A policy you do not understand is a policy you do not control.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.