Blog

A Prompt Is Not a Policy: guardrails and human approval for AI agents

Your agent wants to refund $5,000. Who says yes?

Chilarai Mushahary

Co-founder, CTO

AI AgentOct 8, 2026

An agent wants to refund a customer $5,000. It has the right tool. It has the charge ID. It knows how to call Stripe. Should it be allowed to?

Maybe. But that's not a question the model should answer for itself.

A prompt can say "never refund more than $500". That's an instruction, not a guarantee. The model can misread it, lose it in a long context, or be talked out of it by a message that looks convincing. We wanted the rule to live somewhere the model can't change, and to be checked by code on every call.

Our first version of policies didn't get there:

  • Rules were written per provider, so the same idea had to be written three times.
  • Rules couldn't remember earlier calls, so spend limits and "only what you created" weren't possible.
  • You couldn't try a rule before turning it on.
  • In the QA pass we found that demo mode skipped field-based rules entirely, so a rule that seemed to work in a demo had never really run.

One file, checked on every call

Policies live in .swytchcode/integrations/policies.json. Every call is checked against them before it's sent.

{
  "version": 2,
  "lists": {
    "personal_domains": ["gmail.com", "yahoo.com", "outlook.com"]
  },
  "policies": [
    {
      "id": "no-personal-email",
      "target": ["customers.customer.create", "sendgrid.mail.send"],
      "when": { "field": "$email_domains", "operator": "in", "value": { "$list": "personal_domains" }, "ignore_case": true },
      "action": {
        "type": "POLICY_BLOCKED",
        "message": "Customers with a {{$email_domains}} address are not allowed",
        "hint": "Use the customer's business email address"
      }
    }
  ]
}

A policy has a target, a when condition and an action. Conditions support comparisons, lists, string matching, time windows, and all, any and not to combine them. The full syntax is in the policy rules docs.

The part that makes one rule work across providers is the built-in fields. $email_domains collects the domain of every email address in the request, however deep it is. So the rule above covers Stripe and SendGrid without knowing that one API calls the field email and the other personalizations[0].to[0].email.

This is the real result when an agent tries [email protected] (exit code 6):

{
  "error": "blocked by policy \"no-personal-email\": Customers with a gmail.com address are not allowed",
  "category": "policy_denied",
  "source": "policy",
  "hint": "Use the customer's business email address",
  "suggested_action": "this call was blocked by a configured guard and was not executed - do not retry it or try to work around the guard; report to the user which guard blocked it. A human can review guards with: swytchcode policy list"
}

The hint is for whoever reads the error. Usually that's the agent, which can then fix its own request.

Rules that remember

Most guardrails are stateless: "don't do X". Real systems often need rules that depend on what already happened: "you can do X, but only on things you created", or "you can spend up to $500 today". A prompt can't guarantee either, because the model would have to keep an accurate count across sessions. A policy can, because the count is kept by code.

Policies can look at earlier calls with rate, sum, repeat, called_before and returned_by. A daily spend limit:

{
  "id": "daily-spend-cap",
  "target": ["stripe.payment_intent.create"],
  "when": { "operator": "sum", "field": "amount", "window": "24h", "max": 50000, "per": ["currency"] },
  "action": { "type": "QUOTA_EXCEEDED", "message": "Daily spend of {{$sum}} {{currency}} would exceed {{$limit}}" }
}

This next one lets an agent delete a sandbox only if the agent created it:

{
  "id": "delete-only-own-sandboxes",
  "target": ["e2b.sandbox.delete"],
  "when": { "operator": "not", "conditions": [{
    "field": "sandbox_id", "operator": "returned_by",
    "value": { "tools": ["e2b.sandbox.create"], "field": "sandbox_id" }, "window": "7d" }] },
  "action": { "type": "POLICY_BLOCKED", "message": "Only sandboxes the agent created can be deleted" }
}

returned_by remembers values from earlier successful responses. The agent can clean up its own sandboxes, but not anyone else's. That's permission based on what the agent has actually done, not on what it says it did.

Two details matter here. A retried call is counted once, so a flaky provider doesn't eat into your limit. And when a policy limit is hit, the error says "source": "policy", so an agent doesn't mistake it for the provider's own 429:

{
  "error": "blocked by policy \"new-customers-per-hour\": At most 3 new customers an hour",
  "category": "rate_limit",
  "source": "policy",
  "retry_after": 3600
}

Changing a call instead of blocking it

Sometimes the right answer isn't "no", it's "yes, but". MODIFY changes the call and lets it through. This one tags every customer the agent creates:

{
  "id": "tag-agent-customers",
  "target": ["customers.customer.create"],
  "when": { "field": "metadata.source", "operator": "not_exists" },
  "action": { "type": "MODIFY", "message": "tagged as agent-made",
              "set": { "metadata.source": "agent" } }
}

A real dry run shows the change and what would be sent:

$ swytchcode exec customers.customer.create --dry-run --body '{"email":"[email protected]"}'
policy "tag-agent-customers" changed the call: set metadata.source to "agent" (tagged as agent-made)
{"body":"email=a%40acme.com&metadata%5Bsource%5D=agent","headers":{"Authorization":"[REDACTED]","Content-Type":"application/x-www-form-urlencoded"},"method":"POST","url":"https://api.stripe.com/v1/customers"}

Guardrails don't stop at the request

Most people think of a policy as deciding whether a request is allowed. But an agent can be allowed to make a call and still shouldn't see every byte of the response.

A policy with "stage": "response" runs on the response before the agent sees it:

{
  "id": "hide-emails",
  "stage": "response",
  "target": ["customers.customer.list"],
  "when": { "field": "$status_code", "operator": "==", "value": 200 },
  "action": { "type": "REDACT", "message": "emails hidden", "detect": ["email"] }
}

The real output:

{
  "status_code": 200,
  "data": {
    "object": "list",
    "data": [
      { "id": "cus_1", "name": "Jane", "email": "[REDACTED]" },
      { "id": "cus_2", "name": "Raj",  "email": "[REDACTED]" }
    ],
    "has_more": false
  },
  "policy_notes": ["policy \"hide-emails\" hid 2 value(s) in the response: emails hidden"]
}

policy_notes tells the agent something was hidden, so it doesn't think the data is missing and go looking for it another way.

The detectors check more than the format. A card number has to pass the Luhn check and an IBAN its checksum, so a 16-digit order id isn't redacted by mistake. Response policies can also shorten long lists or hide the whole response. When the response is hidden, the agent is told the call was made and may have taken effect, so it doesn't run it again.

When in doubt, block

A rule that quietly stops working is worse than having no rule.

People stop watching rules they trust. So if a rule can't be checked, the call doesn't run. If policies.json is broken, every call stops:

{
  "error": "policies.json is invalid - run `swytchcode policy validate` to diagnose",
  "category": "policy_error",
  "suggested_action": "the guard could not be evaluated (check the policy field, regex, or value types) - run: swytchcode policy validate"
}

The same goes for a single call when a condition can't be checked, for example when a field holds text but the rule expects a number. policy validate catches type mistakes like that before they reach production. To run without policies, you remove the file. You never get there by accident.

Human approval

Some calls need a person to decide. But if every agent action needs approval, people stop reading the approvals and click "yes" on everything. The goal isn't a person in every loop. It's a person's judgment at the points where judgment matters.

So approval is a policy like any other, scoped to the calls that need it:

{
  "id": "large-refunds",
  "target": ["refunds.refund.create"],
  "when": { "field": "amount", "operator": ">", "value": 100000 },
  "action": { "type": "REQUIRES_APPROVAL", "message": "Refunds over $1,000 need approval" },
  "reuse": { "for": "24h", "same": ["charge"] },
  "approval_timeout": "2h"
}

When an agent tries a refund that matches:

  1. The call is held, and a request goes to your team's Slack or Telegram channel. It shows what the call does, who asked for it and, for an end user's call, whose account it's for.
  2. The CLI exits with 7, so the agent knows the call is waiting, not failed:
Approval requested for refunds.refund.create (policy "large-refunds"). Request 3f9a1c2e7b40.
  A background process is watching and will run this command automatically once it is approved - you do not need to run it again.
  1. If it's approved, the exact call runs once. If it's denied, it doesn't run. Each request is tied to a fingerprint of the tool, the policy and the arguments, so one approval can't be used for a different call.
  2. If the agent asks again while the request is still waiting, nothing new is sent.

The two options at the bottom of the rule are what keep approvals meaningful:

  • reuse lets one approval cover matching calls for a while. Here, further refunds on the same charge for 24 hours. The person approves the decision once, not every call that follows from it.
  • approval_timeout stops a late approval from running the call. A "yes" that arrives the next morning may be worse than no answer at all.

More on the flow is in the human approval docs.

Trying a rule first

Monitor mode records what a policy would have done, without doing it:

{ "id": "new-rule", "mode": "monitor", "...": "..." }

You can run a new rule against real traffic for a week, check the audit log, then turn it on.

You can also put tests in the file:

"tests": [
  { "args": { "email": "[email protected]" }, "expect": "block" },
  { "args": { "email": "[email protected]" }, "expect": "allow" },
  { "name": "subdomain", "args": { "email": "[email protected]" }, "expect": "block" }
]
$ swytchcode policy validate
× validation errors:
  • policy "no-personal-email" test 3 (subdomain): expected block, got allow
error: 1 of 3 policy test(s) failed

The rule only matches exact domains, so mail.yahoo.com gets through. It's much better to catch that in CI than in production. Tests can also include earlier calls, for rules that remember.

Policies vs execution settings

We keep two kinds of settings apart. policies.json decides whether a call runs, and in what form. Each provider's execution_policy decides how it's sent: retries, timeouts and idempotency. A policy never retries anything, and a retried call is never counted twice by a policy.

Summary

Two ideas shaped this work. First, when a rule can't be checked, block the call. Second, people should approve decisions, not every click.

Underneath both is a progression we kept coming back to:

  • A prompt tells the model what we want.
  • A policy tells the execution layer what is allowed.
  • A policy test tells us whether the rule actually works.

That's why we treat policies like code. They live in a file, they go through pull requests, they have tests, and they fail closed when they can't be checked.

At Swytchcode, we see policies as what makes it safe to give an agent real access in the first place. You write the rules once, test them like code, and keep a person in the loop for the calls that matter.

Give this prompt to your agent and get started.

More from the blog

Ready to make your agent's tool calls reliable?

Give this prompt to your agent and get started.