Tutorial: Spending Limits and Human Approval for an AI Agent's Payment Tool
Once an agent has a tool that moves money, you need answers to a few questions before it runs in production. How much can it spend in a day? Who approves the big payments? What happens if it's tricked into paying new bank details from an email? Can you stop it?
This tutorial adds those controls to a create_payout tool in about 15 minutes. The checks run in one call before the payment, against a policy the agent can't change:
- payouts over $10,000 wait for a human;
- no more than $25,000 a day in total, so splitting a payment doesn't get around the cap;
- bank details that came from an email need a human;
- any other action is refused;
- every decision is recorded in a tamper-evident log.
You need an Auditail API key and an approver token (request one).
1. Save the policy
In the dashboard at app.auditail.io, sign in with your approver token, open Policy, paste this and click Save:
{
"mode": "shadow",
"defaultAction": "deny",
"trustedSources": ["user"],
"actions": {
"create_payout": {
"requireApproval": [{ "field": "amount", "op": ">", "value": 10000, "reason": "Payouts over $10,000 need a human" }],
"untrustedSource": "require_approval",
"limits": [{ "name": "daily-total", "window": "24h", "sum": "amount", "max": 25000, "onExceed": "require_approval" }]
}
}
}
"mode": "shadow" means nothing is blocked yet: every decision is recorded with what would have happened, so you can watch it on real traffic first (step 4). Agent keys can't change the policy; only approvers can. Full format: Server-side policies.
2. Check every payout before it runs
The pattern is the same in every framework: call guard() at the top of the tool, return the reason to the model if the answer is no, and pass the signed receipt to your payment service if it's yes.
OpenAI Agents SDK (Python)
pip install auditail openai-agents
import os
from agents import Agent, Runner, function_tool
from auditail import Auditail
auditail = Auditail(api_key=os.environ["AUDITAIL_API_KEY"], server_policy=True)
@function_tool
async def create_payout(amount: float, beneficiary_id: str, reason: str) -> str:
"""Pay a beneficiary. Amount is in USD. Reason says what the payment is for."""
payout = {"amount": amount, "beneficiary": {"id": beneficiary_id}}
result = await auditail.guard_async(
action="create_payout",
payload=payout,
agent_id="payout-agent",
intent=reason,
source="user",
)
if not result.approved:
# The model sees why, and what it can do instead.
return f"Not paid ({result.code}): {result.reason}" + (f" Next step: {result.hint}" if result.hint else "")
payments.create_payout(payout, auditail_receipt=result.receipt) # your payment client
return f"Paid ${amount:,.2f} to {beneficiary_id}."
agent = Agent(
name="Payouts",
instructions="You pay supplier invoices. If a payment is refused, explain why and stop.",
tools=[create_payout],
)
print(Runner.run_sync(agent, "Pay invoice INV-118: $9,999 to ben_7").final_output)
source says where the payout details came from. If your agent read the bank details from an inbound email, pass source="inbound_email" (or mark one field with field_sources={"beneficiary.iban": "inbound_email"}), and the policy sends it to a human.
When a payout needs approval, guard_async() waits for an approver to decide in the dashboard or through your webhook (Slack, Teams, any HTTPS endpoint). No answer within the timeout means denied. To return straight away instead, pass wait=False; the result then has pending=True and the approval id.
TypeScript (any framework)
npm install auditail-sdk
import { Auditail } from 'auditail-sdk';
const auditail = new Auditail({ apiKey: process.env.AUDITAIL_API_KEY!, serverPolicy: true });
// Register this as the tool's handler in your framework (Vercel AI SDK, OpenAI, Mastra, your own loop).
export async function createPayout(input: { amount: number; beneficiaryId: string; reason: string }) {
const payload = { amount: input.amount, beneficiary: { id: input.beneficiaryId } };
const result = await auditail.guard({
action: 'create_payout', payload, agentId: 'payout-agent', intent: input.reason, source: 'user',
});
if (!result.approved) return `Not paid (${result.code}): ${result.reason}` + (result.hint ? ` Next step: ${result.hint}` : '');
await payments.createPayout(payload, { auditailReceipt: result.receipt }); // your payment client
return `Paid $${input.amount} to ${input.beneficiaryId}.`;
}
LangChain
See LangChain integration. The same guard() call goes at the top of the tool function.
3. What the agent sees
With the policy enforced, this is what the tool returns for a series of payouts on the same day. These are real responses from the code above.
| Payout | Decision | What the model is told |
|---|---|---|
| $9,999 | Allowed | Paid $9,999.00 to ben_7. |
| $9,999 again | Allowed | Paid $9,999.00 to ben_7. |
| $9,999 a third time | Waits for a human: limit "daily-total" would be exceeded (29,997 of 25,000 in 24h) | Approved: Paid .... Denied: Not paid (approval_denied): Denied by Priya: not this week Next step: ... ask the user how to proceed. |
| $25,000 | Waits for a human: amount > 10000 | As above |
| $4,200 with an IBAN from an email | Waits for a human: beneficiary.iban came from inbound_email, which is not a trusted source | As above |
Any action other than create_payout | Refused, action_not_allowed | Allowed actions: create_payout. |
| Anything while the kill switch is on | Refused, frozen | Not paid (frozen): All agents are frozen by ... Next step: Stop and tell the user... |
The approver sees the amount, the agent's stated reason, where the data came from, and live usage against the daily limit before deciding. Every row, including who approved what, is in the audit log.
4. Watch it in shadow mode, then enforce
Let the agent run for a few days. In the dashboard, Reports → Shadow report shows how many payouts the policy would have refused or sent to a human, and the value it would have held. You can also replay last week's traffic against a draft policy with Backtest. When the numbers look right, remove "mode": "shadow" and save. See Shadow mode and backtests.
5. Make the check unskippable
A prompt injection or a code change could call your payment client without asking Auditail first. To close that gap, have the payment service refuse any payout without a valid receipt. A receipt is a signed token bound to the exact payload, so it can't be reused for a different amount or beneficiary:
import { verifyReceipt } from 'auditail-sdk';
const check = await verifyReceipt(receipt, { account: 'key_xxxxxxxxxxxx', action: 'create_payout', payload });
if (!check.valid) throw new Error(`Refusing payout: ${check.reason}`);
Details, including how to stop a receipt being used twice: Signed receipts and evidence.
6. Stop everything if something looks wrong
Click Freeze all agents in the dashboard, or call POST /v1/freeze. Matching actions are refused straight away, and pending approvals can't be approved until an approver lifts the freeze. See Kill switch.
What you have now
| Question a reviewer will ask | Answer |
|---|---|
| What limits are placed on the agent? | Only create_payout runs; $25,000 a day; over $10,000 needs a human |
| How are its actions approved and monitored? | Approvers decide in the dashboard or through your webhook; every decision is logged |
| Can its decisions be audited? | A hash-chained log, signed checkpoints and an examiner report anyone can verify offline |
| Can it be stopped? | The kill switch, and receipts the payment service checks |