Refunds need human approval. Where do you enforce that in an agent?
Question
A shop's support agent can call lookup_order, prepare_refund and issue_refund. Policy: every refund needs a person's approval. The system prompt says "Always get approval before calling issue_refund". The workflow has these steps:
- start → prepare
- prepare → approval → refund
- prepare → recovery, when a tool call fails
- recovery → prepare (try again), or recovery → refund (finish a refund that timed out)
The recovery step was added last month.
- Show how a refund can now happen without approval.
- Where do you enforce the approval, and what must an approval record hold?
Show hints (3)
- "FOLLOW THE ARROWS"
Cross out the approval step. Can you still get from start to refund?
- "WHO SEES EVERY CALL"
The prompt, the plan and the workflow can all change. Which piece of code runs on every refund, whatever path led to it?
- "WHAT TO BIND"
An approval for a refund of 40 on order A-17 should not pay 400, or pay twice. What must the record hold so the refund code can check that?
Show checked explanation
Through recovery: start → prepare → recovery → refund never passes approval. Enforce it inside issue_refund or the payment service: refuse unless a person approved this exact order and amount and the approval hasn't expired. That covers every path, even ones added later.
approvals = { # written by the approval screen, never by the model
"ap-1": {"order": "A-17", "amount": 40, "expires": 900, "result": None},
}
def issue_refund(order, amount, approval_id, now):
a = approvals.get(approval_id)
if a is None or now > a["expires"]:
return "denied: no valid approval"
if (a["order"], a["amount"]) != (order, amount):
return "denied: approval is for another refund"
if a["result"] is None: # first use: the real payment call goes here
a["result"] = f"refunded {amount} on {order}"
return a["result"]
calls = [("A-17", 40, None, 10), ("A-17", 400, "ap-1", 20),
("A-17", 40, "ap-1", 30), ("A-17", 40, "ap-1", 95)]
for call in calls:
print(*call[:3], "->", issue_refund(*call))A-17 40 None -> denied: no valid approval A-17 400 ap-1 -> denied: approval is for another refund A-17 40 ap-1 -> refunded 40 on A-17 A-17 40 ap-1 -> refunded 40 on A-17
Code run on CPython 3.12 against the example above. Checked by an editor other than the author.
Walkthrough
The policy needs every path to pass approval. Cross out the approval step and see what is left:
- start → prepare → approval → refund: approved.
- start → prepare → recovery → refund: no approval. This is the bypass.
- start → prepare → recovery → prepare → approval → refund: approved, just longer.
The system prompt doesn't close the gap. The model usually follows it, but a long chat, a confusing error or injected text can lead it straight to issue_refund. Next month someone may add another path.
Put the check where the money moves. issue_refund itself refuses to run without a valid approval. Which path, plan or prompt led there no longer matters.
A person gives the approval in a separate screen, and your system stores it. The model never writes it. The record holds:
- what was approved: order
A-17, amount 40; - who approved it, someone other than the requester;
- when it expires, here after 900 seconds (15 minutes);
- the result, once it has been used.
| call | result |
|---|---|
| refund 40, no approval (the recovery path) | denied |
| refund 400 with the approval for 40 | denied |
| refund 40 with the approval | refunded |
| the same refund again after a timeout | the first result, no second refund |
An approval older than 15 minutes is refused like a missing one. A retry gets the first result back instead of paying again. Send the approval id to the payment provider as the idempotency key too. Then a timeout that hid a successful refund can't pay twice.
Show the approver the real order and amount from your database, not the model's summary, which can be wrong or manipulated.
Common mistakes
- Letting the model pass
approved=Trueas a tool argument. The model can write anything, so the refund code must look the approval up in your own store. - Checking approval only in the planner or the prompt. A recovery path, a retry or next month's new step goes around it.
- Approving "a refund for A-17" without the amount. The model can then change 40 to 400, and the approval still matches.
- Approvals that never expire or can be reused. An old click then authorizes a refund nobody is looking at.
Follow-up questions
- "How would you find bypasses in a workflow you already have?" Treat the steps as a graph. Remove the approval node and search from start, for example with breadth-first search. If refund is still reachable, that path is a bypass. Run this on every workflow change, but keep the check in
issue_refund: the graph may miss a path. - "Approvals slow support down. Can small refunds skip them?" Yes, if the rule lives in the same refund code: for example, no approval under 20, with a daily cap per agent and per customer. The model can't move the threshold. Log every automatic refund and review a sample.
What a strong answer covers
Finds the bypass through recovery, explains why a prompt or diagram can't guarantee every path, and enforces approval in the refund code. Binds the approval to the exact order and amount, with an approver, an expiry and one use. Makes retries idempotent.
Open in interactive practice deck →