Module 05 · Lesson 5.4
Human-in-the-Loop Approval and Escalation
On this page
- What you will learn
- What is an approval gate in an AI agent?
- Which agent steps need a person's approval?
- How to design an approval request people can answer
- Avoid approval fatigue: ask only for what matters
- Escalate to the right person with the right context
- Keep an audit record of every decision
- An approval gate and an escalation rule in Python
- Conclusion and your next step
- Common errors and fixes
- Validation checklist
- Hands-on exercise
- Knowledge check
- Frequently asked questions
- References
Picture a builder fixing your kitchen. Halfway through, they find a water pipe inside the wall they planned to remove. A good builder does not decide alone. They call you and say: "This wall hides a pipe. Moving it costs 400 more. If you say yes, I start tomorrow. If you say no, I leave the wall as it is." You answer in ten seconds, because you were given what you needed.
An AI agent needs the same habit. Some steps are too risky to run on the agent's own say-so, and some cases are too hard for it. This lesson shows you how to build approval gates (a point where a person must say yes) and escalation (handing a case to the right person). Most of it needs no coding. One short Python example at the end shows both ideas in about 35 lines.
What you will learn
- Decide which agent steps need a person's approval and which can run alone.
- Design an approval request that a busy person can judge in seconds.
- Set safe defaults, so no answer or an unclear answer never lets a risky step run.
- Route a hard case to the right person and keep a record of every decision.
Before you start
- The previous lesson, Sequential, Parallel and Conditional Tool Execution.
- The Module 3 lab, Practical Lab: Build an Agent That Uses Two Tools, where a person calls
approve()on a waiting request. - No coding experience is needed for most of this lesson.
- Optional: Python 3.10 or later, if you want to run the example yourself.
What is an approval gate in an AI agent?
In the Module 3 lab, the tool request_return did not create a return. It only added a request to a waiting list called PENDING. A member of staff then called approve(). That pause is an approval gate: a point in the agent's work where a person must say yes before a risky step runs.
Think of a lift that will not move until someone turns a key. The agent can press the button as often as it likes. Nothing happens until a person with the key says so.
- Approval gate
- A point where the agent stops and waits. The step runs only after a person says yes.
- Human-in-the-loop
- A design where a person is part of the process at chosen points, not only at the start and the end.
- Escalation
- Handing a case to a person, with the facts they need, because the agent should not or cannot finish it.
- Approver
- The person who is allowed to say yes or no to a request. Which person depends on the request.
- Agent proposes a step
For example: save the report
- Code checks the step
Does it need approval?
- Request is shown
What, why, evidence, yes and no
- Person decides
Yes, no, or no answer
- Step runs or stops
Only yes runs it. The decision is recorded.
The agent prepares the request. Only a person's yes lets the step run. Every other path ends safely.
Which agent steps need a person's approval?
Not every step needs a person. If you ask for approval on everything, the agent is no faster than a person doing the work. Ask on the steps where a mistake is costly or hard to undo.
| Kind of step | Example | Approval? |
|---|---|---|
| Reading information | lookup_order, read_doc | No. It changes nothing. |
| Writing or saving | save_report, request_return | Yes. Something new now exists. |
| Moving money | A refund, a discount, a payment | Yes, and often a senior person. |
| Messages to customers | An email that speaks for the shop | Yes, until you trust the wording. |
| Anything hard to undo | Deleting data, cancelling an order | Yes. You cannot take it back. |
The research scenario in this module follows the same rule. search_docs and read_doc are read-only, so they run alone. save_report is a write, so it always waits for a person.
How to design an approval request people can answer
Go back to the builder and the hidden pipe. The call worked because it was short and complete. An approval request should work the same way. The approver is busy, so the request must let them decide in seconds, without hunting for facts.
What a good request shows
- What will happen. Name the step and its inputs, in plain words.
- Why. One sentence that says why the agent wants to do it now.
- The evidence. The sources the agent used, such as the document IDs RS-01, RS-02 and RS-04. The person can open them if they doubt the agent.
- What happens on yes. For example: the report is saved.
- What happens on no. For example: nothing is saved and the agent stops.
A weak request and a strong request
| Weak | Strong |
|---|---|
| "Allow the agent to continue?" | "Save the report titled Battery recommendation? Based on RS-01, RS-02, RS-04. Yes: it is saved. No: nothing happens." |
| A long block of the agent's reasoning | Three short lines the person can read in one breath |
| A button labelled only "OK" | Two clear choices: "Approve and save" and "Do not save" |
Avoid approval fatigue: ask only for what matters
Think of the pop-up on your phone that asks "Allow?" ten times a day. After a week you tap yes without reading. Approval fatigue is exactly that: people who are asked too often stop reading and approve everything. Then the gate protects nothing, and it looks as though it does.
- Ask only for what matters. Keep reads and harmless steps outside the gate.
- Make differences obvious. Highlight what is new or unusual, so a risky request does not look like the last fifty.
- Batch similar requests. Ten return requests that look alike can be one screen with ten rows, not ten pop-ups.
- Keep the default safe. A tired or absent person must never cause a risky step to run.
Safe defaults: when nobody answers
People go to lunch. Phones are off. Sometimes the answer is "maybe" or just a thumbs-up emoji. In all these cases the agent must not act. A safe default is the choice the system makes when it is unsure, and for a risky step it is always "do nothing".
- Set a time limit for the answer, for example one working day.
- When the time is up, the request ends as "not approved". It does not quietly turn into a yes.
- Treat only a clear "yes" as yes. Anything else counts as no.
Escalate to the right person with the right context
Approval is a question the agent asks. Escalation is a handover: the agent cannot or should not finish the case, so it passes it on. You met handover in Define the Agent's Objective, Scope and Success Criteria. Here you decide who receives it.
Not every person can say yes to everything. At Quillfeather Cycles, the staff-only note KB-15 says refunds above 500 must be approved by a store manager. So a refund of 120 can go to the support team, but a refund of 640 must go to a store manager.
| Situation | Who gets it | What they need to see |
|---|---|---|
| Refund of 500 or less | Support team | Order ID, amount, reason, what the customer asked |
| Refund above 500 | Store manager | The same, plus why it is above the limit |
| Safety problem, such as weak brakes | Support team, marked urgent | The customer's words and the order ID |
| The agent cannot find the order | Support team | What was searched and what came back |
A good escalation includes the context: a short summary of what the customer asked, what the agent already did and what it found. Otherwise the person must start from zero, and the customer has to repeat everything.
Keep an audit record of every decision
An audit record is a short note saved for each decision. It answers four questions later: who decided, what they decided about, when, and whether the answer was yes or no. Include the "no answer" cases too.
- Who: the person or the role. Never the agent itself.
- What: the tool and its inputs, or the request ID.
- When: the date and time.
- Result: approved or not approved.
When a customer says "I never agreed to that", or when something goes wrong, the record shows what really happened. Do not put secrets or unneeded personal data in it. Memory Retention, Privacy and Data Lifecycle explains why. Rules differ by country, so follow your organisation's policy.
An approval gate and an escalation rule in Python
The script below builds an approval request for save_report, shows it, and decides three scripted cases: "y", "n" and no answer. It then routes two refunds. Nothing here calls an AI model, and the script gives the same output every time.
AUDIT = [] # one entry for every decision, kept in order
def make_request(tool, args, why, evidence):
return {"tool": tool, "args": args, "why": why, "evidence": evidence}
def show(request):
print("APPROVAL NEEDED:", request["tool"], request["args"])
print(" Why:", request["why"])
print(" Evidence:", ", ".join(request["evidence"]))
print(" If yes: the report is saved. If no: nothing happens.")
def decide(request, answer, who, when):
approved = str(answer).strip().lower() == "y" # None, "n" and anything unclear mean no
AUDIT.append({"who": who, "when": when, "tool": request["tool"], "approved": approved})
print(" Decision:", "approved" if approved else "NOT approved", "|", AUDIT[-1])
return approved
def route_refund(amount):
return "store manager" if amount > 500 else "support team" # KB-15: above 500
request = make_request("save_report", {"title": "Battery recommendation"},
"Research is finished and the report is ready to store.",
["RS-01", "RS-02", "RS-04"])
show(request)
for answer, when in [("y", "10:00"), ("n", "10:05"), (None, "10:10")]:
if decide(request, answer, "analyst-1", "2026-11-18 " + when):
print(" -> save_report runs")
print("Refund 120 goes to:", route_refund(120))
print("Refund 640 goes to:", route_refund(640))Runs offline with any Python 3.10 or later. Save it and run python approval_gate.py.
What each part does
AUDIT = []is an empty list, an ordered row of items. Every decision is added to it.make_request(...)builds the request as a dictionary, a set of labelled entries: the tool, its inputs, why, and the evidence.show(request)prints a short summary for the person: what, why, evidence, and what yes and no mean.decide(...)is the gate.str(answer).strip().lower() == "y"isTrueonly for a clear "y". The valueNone(no answer, as after a timeout), "n" or anything unclear givesFalse.AUDIT.append({...})records who, when, which tool and the result, before anything else happens.route_refund(amount)is the escalation rule from KB-15 as code: above 500 goes to the store manager.- The
forloop runs three scripted answers. Only the first one printssave_report runs. - The times are written into the script, so the output never changes between runs.
APPROVAL NEEDED: save_report {'title': 'Battery recommendation'}
Why: Research is finished and the report is ready to store.
Evidence: RS-01, RS-02, RS-04
If yes: the report is saved. If no: nothing happens.
Decision: approved | {'who': 'analyst-1', 'when': '2026-11-18 10:00', 'tool': 'save_report', 'approved': True}
-> save_report runs
Decision: NOT approved | {'who': 'analyst-1', 'when': '2026-11-18 10:05', 'tool': 'save_report', 'approved': False}
Decision: NOT approved | {'who': 'analyst-1', 'when': '2026-11-18 10:10', 'tool': 'save_report', 'approved': False}
Refund 120 goes to: support team
Refund 640 goes to: store managerLook at the third decision. Nobody answered, and the result is still "NOT approved". That is the safe default at work. The refund of 640 went to the store manager because a rule in code said so, not because a model guessed.
Conclusion and your next step
Let the agent do the routine work and keep people in charge of risky steps. Ask for approval on writes, money, customer messages and anything hard to undo. Show approvers what, why, evidence, and what yes and no mean. Make "no answer" mean no. Route hard cases to the right person, and record every decision.
Your next step: list the steps of an agent you are designing, and mark each as "runs alone" or "needs approval". For each approval, write the three-line request a person would see. Then continue to Managing Long-Running Tasks and Checkpoints, where you learn what happens to a waiting task when the program stops.
Want more? Read Plan-and-Execute Workflows to see where approval points fit inside a plan, or use the Agent Launch Safety Checklist before you connect an agent to real systems.
Common errors and how to fix them
Approvers click yes on everything without reading.
Why it happens: The agent asks about too many steps, or every request looks the same.
Fix: Remove approvals for read-only steps, batch similar requests and highlight what is different or unusual.
A risky step ran although nobody approved it.
Why it happens: The rule "ask first" was only written in the instructions, or no answer was treated as yes.
Fix: Put the check in code, so the tool refuses to run without a recorded yes. Treat no answer and unclear answers as no.
The approver asks "what am I agreeing to?"
Why it happens: The request has no clear action, reason or evidence.
Fix: Show what will happen, why, the sources, and what happens on yes and on no, in a few short lines.
A large refund was approved by someone who is not allowed to approve it.
Why it happens: All cases were sent to the same person, or the model chose who to ask.
Fix: Write the routing rule in code, for example above 500 goes to a store manager, and test it.
Validation checklist
Tick each item once you have confirmed it.
Hands-on exercise
Add a second approval rule and an escalation
Extend approval_gate.py. Add a second tool, send_email, that also needs approval. Then add a rule that routes a refund of exactly 500 to the support team, and a refund of 500.01 or more to the store manager. Add a time limit by treating the answer "timeout" as no answer.
You will need
- Your working copy of
approval_gate.pyfrom this lesson. - KB-15: refunds above 500 must be approved by a store manager.
- Test answers: "y", "Y ", "yes please", "n", "timeout" and None.
Acceptance criteria
Your work is done when every one of these is true.
Hints (3)
- Read the check in
decide. Does "yes please" equal "y"? - Compare with
>not>=for the refund limit, because KB-15 says "above 500". - Test the edge value 500 on purpose. Most routing mistakes happen at the edge.
Show a model answer
The existing check str(answer).strip().lower() == "y" already handles most cases: "Y " becomes "y" and passes, while "yes please", "timeout", "n" and None do not equal "y" and are recorded as not approved. That is the point of a strict check: unclear answers are safe by default. For send_email, call make_request("send_email", ...) with its own why and evidence, and run it through the same decide. The refund rule "store manager" if amount > 500 else "support team" already sends exactly 500 to the support team and 500.01 to the store manager. Checking the edge value 500 shows whether you used > correctly. Print AUDIT at the end to confirm that all six decisions are there, approved or not.
Knowledge check
Choose an answer, then check it. Nothing is recorded — this is for you.
Show the answer and explanation
Answer: B. No clear yes means no. Running the step is tempting because it keeps work moving, but it lets a risky action happen with nobody's agreement. The model's opinion cannot replace a person's approval.
Show the answer and explanation
Answer: B.
save_reportcreates something new, so it is a write. Reading a document is tempting to guard because it uses a tool, but it changes nothing, and extra approvals cause approval fatigue.Show the answer and explanation
Answer: A. KB-15 says refunds above 500 need a store manager, and a rule in code applies it every time. Letting the model choose is tempting, but its choice can change from run to run and cannot be tested the same way.
Frequently asked questions
What does human-in-the-loop mean for AI agents?
It means a person takes part at chosen points, usually before a risky step runs. The agent does the routine work, such as gathering facts and preparing a request. The person makes the final decision, such as approving the save or the refund.
When should an AI agent ask a human for approval?
Ask before steps that write or save something, move money, send messages to customers or are hard to undo. Do not ask for harmless reads, or people will stop paying attention.
What is the difference between approval and escalation?
Approval is a yes-or-no question for a step the agent wants to take. Escalation is a handover of a whole case to a person, because the agent should not or cannot finish it. An escalation can include approvals, but a person owns the case.
What happens if the human never answers an approval request?
The request ends as not approved after a time limit, and the risky step does not run. The agent can tell the user it is waiting for a person. Never let silence count as a yes.
- Written by
- PromptFable Editorial
- Last updated 18 Nov 2026
- Review
- Reviewed by Waseem Nadir, Technical Reviewer
- Last reviewed 27 Nov 2026
References
Primary sources for the technical details in this lesson. Vendor platforms change — check the official page if anything here looks different from what you see.
- LLM06:2025 Excessive Agency(opens in a new tab)
OWASP Foundation · Official documentation · Why an agent should have limited tools and why risky actions need a person's approval.
- OWASP Top 10 for LLM Applications(opens in a new tab)
OWASP Foundation · Official documentation · The wider list of risks for applications built on language models.
- Building effective agents(opens in a new tab)
Anthropic · Official documentation · Covers checkpoints where an agent pauses for human feedback.
- AI Risk Management Framework(opens in a new tab)
NIST · Official documentation · A general framework for managing AI risks, including human oversight.
- Python tutorial: data structures(opens in a new tab)
Python Software Foundation · Official documentation · Background for the list and dictionary used in the example.
PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.