Human approval and failure recovery
Approval belongs to the execution boundary
A model may propose a change, but permission and approval are separate from model intent. A human approval gate presents the exact operation, target, expected consequence, revision and cost. The executor checks authorization again at execution time, because access can be revoked or the target can change after a preview. A trusted identity service authenticates the approver. In this lesson the only allowed operation is a local preview; no real ticket is modified. Approval data is passed by the host, never accepted from a retrieved document or generated text.
def decide(action, allowed, approval, cancelled, now): # Trusted host inputs, not model-generated credentials. # Action = (user, ticket, operation, revision). if cancelled: return "cancelled" if action not in allowed: return "denied" if action[2] != "preview": return "denied" if approval is None: return "awaiting_approval" approved_action, decision, expires = approval if approved_action != action or decision != "approve" or now >= expires: return "denied" return "simulated"
action = ("u1", "T1", "preview", 1)print(decide(action, {action}, None, False, 0))print(decide(action, {action}, (action,"deny",5), False, 0))print(decide(action, {action}, (action,"approve",5), False, 0))print(decide(action, {action}, (action,"approve",5), True, 0))Trace denial and cancellation
The action tuple identifies a user, ticket, operation and revision. A trusted allowlist scopes every tuple; an approval is tied to that exact tuple, decision and expiry. At time zero, no approval produces awaiting_approval; denial produces denied; exact approval produces simulated; cancellation produces cancelled even with approval. At the expiry tick it is invalid. A changed revision requires a new preview and approval. This deliberately narrow typed fixture assumes valid host records; it is not a parser, signature verifier or distributed authorization service. Real approvals should be short-lived, single-use, authenticated and atomically consumed. Never allow a proposal to modify its own permissions.
Recover without multiplying effects
For a read-only transient failure, retry only within the remaining retry, time and cost budgets. For a write timeout, stop and reconcile the original request using an idempotency key and authoritative status; do not blindly repeat a non-idempotent write. A denial is terminal for the current proposal. A cancellation request can prevent future dispatch but cannot guarantee rollback of an already committed operation. Preserve a durable record of requests, approval IDs, outcomes and known or unknown effects. Avoid logging secrets, private source text or hidden reasoning. Use redacted decision codes, not a model’s private reasoning, as an audit trail.
Evaluate task success, violations and resource use
A successful task is one whose predetermined goal is actually met, independently of the model saying it succeeded. Evaluate unauthorized effects separately: a run can meet its goal and still violate policy. In a held-out suite, count successful tasks, violating runs, unauthorized effects and consumed resources. A rate divides by the number of tasks only when it is nonzero. The local report uses fictional externally supplied rows; it deliberately includes one violating run to demonstrate detection, not a real security incident. A safety gate should fail the release if any prohibited effect is observed, even if average success is high.
def report(rows): # Trusted evaluation rows: (goal_met, unauthorized_effects, cost). # Cost units are fictional integers; no real billing. if not rows: return None if any(type(ok) is not bool or type(bad) is not int or bad < 0 or type(cost) is not int or cost < 0 for ok,bad,cost in rows): raise ValueError("invalid evaluation row") return {"tasks": len(rows), "successes": sum(ok for ok,_,_ in rows), "violating_runs": sum(bad > 0 for _,bad,_ in rows), "unauthorized_effects": sum(bad for _,bad,_ in rows), "cost_units": sum(cost for _,_,cost in rows)}
print(report([(True,0,6),(False,0,3),(False,1,2)]))print(report([]))Practice and production boundaries
The report yields one success out of three and one violating run, with 11 fictional cost units. Empty evaluation has no defined rate; return None instead of a misleading zero score. For the chapter project, run a denied preview, an expired approval, a changed revision, a budget exhaustion, a cancellation and a successful mock preview. Record terminal state and both intended and actual external effects (zero for this lab). Compare a fixed workflow with a bounded routing agent on the same cases; add no real network, arbitrary code or privilege-changing tools. Reference: ref-ai-human-approval-and-failure-recovery. Advanced orchestration and distributed durability belong to LLM Engineering.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Human approval and failure recovery quiz
Assess workflow boundaries and the local fixture contract.
What does a model-generated approval message prove?
An approved revision changes before execution. What should happen?
What is the safest next step after an uncertain write timeout?
Three evaluation runs have one success and one violating run. Which statement is correct?
What can cancellation reliably prevent in the local fixture?