> ## Documentation Index
> Fetch the complete documentation index at: https://docs.brane.membranelabs.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Policy Control For AI Agents

> Brane gives AI agents policy control by evaluating Python policies before and after capability execution.

Policy control for AI agents means enforcing explicit rules when an agent attempts to act. Brane provides policy control by evaluating Python policy functions before and after capability execution.

Policies receive a structured [PolicyContext](/concepts/policy-context) and return a structured [Decision](/concepts/decision).

## Policy Control Loop

```text theme={null}
Capability + AgentAction + PolicyContext -> Policy -> Decision
```

This loop lets teams decide what an agent can do based on:

* Agent identity
* Principal identity
* Tenant
* Environment
* Capability risk
* Input arguments
* Output
* Runtime metadata
* Application-specific policy data

## Before Policies

Before policies run before the action executes. Use them to prevent unsafe side effects.

```python theme={null}
@runtime.before_capability("refund_customer")
def refund_limit(ctx):
    if ctx.arg("amount_usd", 0) > 100:
        return Decision(type="deny", reason="Refund exceeds tenant limit")
    return Decision(type="allow")
```

## After Policies

After policies run after execution and can inspect output. Use them to detect oversized outputs, unexpected schemas, PII, secrets, or policy violations after the capability returns.

```python theme={null}
@runtime.after_capability("call_model")
def block_secret_leak(ctx):
    if "SECRET_KEY" in str(ctx.output or ""):
        return Decision(type="deny", reason="Possible secret in output")
    return Decision(type="allow")
```

## Policy Control Categories

| Category            | Example policy                           |
| ------------------- | ---------------------------------------- |
| Financial control   | Deny refunds above a tenant limit        |
| Data control        | Allow only SELECT queries                |
| Tenant control      | Block cross-tenant actions               |
| Environment control | Block high-risk capabilities in prod     |
| Tool control        | Deny destructive tools without approval  |
| Output control      | Deny responses containing secrets or PII |

## Related Pages

* [Writing Policies](/policy/writing-policies)
* [Before Capability Policies](/policy/before-capability)
* [After Capability Policies](/policy/after-capability)
* [Policy-as-Code For AI Agents](/guides/policy-as-code-for-ai-agents)
