Velamuvi AIAcademy

Lesson 4 of 6 · Safety

Approval Gates

Build approval gates for AI agents: decide in code what needs sign-off, bind approvals to exact parameters, make them single-use and keep an audit log.

  • 6 min read
  • Advanced
  • Reviewed
In this lesson you will learn
  • Decide in code which actions need human approval
  • Show approvers the exact action, the reason and the evidence
  • Bind an approval to the exact action so it can't be changed afterwards
  • Make approvals single-use, time-limited and denied by default
  • Keep an audit log and avoid approval fatigue

A person signs off

Some actions are too risky to run on the agent's judgement alone: large payments, messages to many people, deleting data, changing permissions. For these, an approval gate pauses the agent until a person agrees.

The Agentic AI Fundamentals course covers when people should be in the loop. This lesson is about building gates that can't be bypassed, because a gate with a loophole is worse than none: everyone believes they're protected.

Gates that hold

Here a payment needs approval. Watch what happens when the action changes after approval, when it's tried twice, and when the approval is used too late:

Try it yourselfPython
import hashlib, json

# Approval gates: a person approves ONE exact action, for a limited time, and every step is logged.
audit = []

def fingerprint(action):
    """A short hash of the exact action. Any change to the action changes the fingerprint."""
    return hashlib.sha256(json.dumps(action, sort_keys=True).encode()).hexdigest()[:12]

def describe(action):
    return f"{action['tool']} {action['amount']} EUR to {action['to']}"

def request_approval(action, reason, now):
    req = {"fp": fingerprint(action), "expires": now + 15 * 60, "status": "pending"}
    audit.append(f"t={now}: approval {req['fp']} requested: {describe(action)} ({reason})")
    return req

def execute(action, req, now):
    if req["status"] != "approved":
        return f"BLOCKED: not approved ({req['status']})"
    if now > req["expires"]:
        return "BLOCKED: approval expired, ask again"
    if fingerprint(action) != req["fp"]:
        return "BLOCKED: action differs from what was approved"
    req["status"] = "used"                                   # one approval, one execution
    audit.append(f"t={now}: executed {describe(action)}")
    return f"done: {describe(action)}"

# The agent proposes a payment; a person approves it
action = {"tool": "pay_invoice", "to": "Supplier Ltd, IBAN ...4821", "amount": 2400}
req = request_approval(action, "over 1,000 EUR", now=0)
req["status"] = "approved"
audit.append(f"t=60: approval {req['fp']} granted by Priya (finance)")

# Later, the agent (perhaps steered by a malicious invoice email) changes the payee before paying
tampered = dict(action, to="New Account Ltd, IBAN ...9999")
print(execute(tampered, req, now=120))
print(execute(action, req, now=120))
print(execute(action, req, now=180))          # the same payment again

# A second payment is approved, but the agent only gets to it an hour later
action2 = {"tool": "pay_invoice", "to": "Printer Co, IBAN ...1177", "amount": 1300}
req2 = request_approval(action2, "over 1,000 EUR", now=0)
req2["status"] = "approved"
print(execute(action2, req2, now=60 * 60))
print("\nAudit log:")
print("\n".join("  " + line for line in audit))

Four rules made the gate hold:

  1. The approval is bound to the exact action. The approval stores a fingerprint (a hash) of the action's parameters. When the agent, perhaps influenced by a malicious invoice email, swapped in a different bank account, the fingerprint no longer matched and the payment was blocked.
  2. One approval, one execution. After the payment ran, the approval was marked used, so the same payment couldn't run twice.
  3. Approvals expire. The second payment was approved but not run until an hour later. Circumstances may have changed, so the agent must ask again.
  4. Everything is logged: who asked, who approved, what ran and when.

What the approver needs to see

An approval is only as good as the decision behind it. Show the approver:

  • The exact action: “Pay 2,400.00 EUR to Supplier Ltd, IBAN ending 4821”, not “Process payment”.
  • The reason: why the agent wants to do it, and which rule triggered the approval.
  • The evidence: the invoice, the purchase order it matches, previous payments to this supplier.
  • What's unusual: “New bank account, first payment to it” deserves a warning at the top.
  • The choices: approve, edit (then re-approve), or reject with a reason the agent can use.

Avoiding approval fatigue

If people approve 200 requests a day, they stop reading them, and the gate becomes a rubber stamp. Keep approvals meaningful:

  • Gate by risk, as in lesson 1, so routine actions don't need approval at all.
  • Batch low-risk items into one review (“approve these 12 small refunds”) while high-risk items get individual attention.
  • Measure approval times and rejection rates. If nothing is ever rejected, ask whether the gate is checking the right things, or whether people are clicking through.
  • Learn from decisions: if a type of request is always approved, consider automating it with a limit; if one is often rejected, fix the agent.

Common mistakes

Practice exercise

Bind an approval to the exact action: the fingerprint must match, so an action changed after approval is refused.

Your solutionPython
import hashlib, json

def fingerprint(action):
    # Return the first 12 characters of the SHA-256 hex digest of
    # json.dumps(action, sort_keys=True), encoded to bytes with .encode()
    pass

approved = fingerprint({"tool": "delete_files", "folder": "/reports/2023"})
requests = [{"folder": "/reports/2023", "tool": "delete_files"},     # same action, keys in another order
            {"tool": "delete_files", "folder": "/reports"}]          # a bigger folder!
for r in requests:
    print("run" if approved is not None and fingerprint(r) == approved else "blocked")
Knowledge check

An approved payment's bank account is changed before it runs. What should the gate do?

Summary

  • An approval gate pauses risky actions until a person approves, enforced in code.
  • Bind approvals to the exact action with a fingerprint; make them single-use and time-limited.
  • Deny by default when there's no answer, and keep an audit log.
  • Show approvers the exact action, reason, evidence and anything unusual.
  • Fight approval fatigue by gating on risk, batching low-risk items and measuring rejections.

Next: prompt injection in agents.

Finished reading? Tick it off to track your progress.