Human-in-the-Loop AI Agents: How to Add Approval Steps Before Sensitive Actions
Originally published on Datamarcos Guides. By Deepesh Mishra, Founder & CEO, Datamarcos · Last reviewed 27 November 2026 Short answer: A human-in-the-loop agent pauses before a risky step, shows a person exactly what it
Originally published on Datamarcos Guides.
By Deepesh Mishra, Founder & CEO, Datamarcos · Last reviewed 27 November 2026
Short answer: A human-in-the-loop agent pauses before a risky step, shows a person exactly what it wants to do, and continues only after that person approves, edits or rejects it. LangGraph, n8n, CrewAI, the OpenAI Agents SDK and Google ADK all support this. The hard part is choosing which actions need approval and blocking the write until it is given.
What is human-in-the-loop in agentic AI?
An AI agent is a model that works towards a goal by choosing and calling tools in a loop (see what is agentic AI if that is new). Some of those tools only read data. Others change something in the real world: they send an email, update a customer record in the ERP, issue a refund, merge code or delete a file.
Human in the loop means a person sits inside that loop for selected steps. The agent proposes an action, the run pauses, a reviewer decides, and the run continues with that decision.
What is the difference between human in the loop and human on the loop?
You will also see human on the loop, which usually means people monitor an agent that acts on its own and step in when something looks wrong. On-the-loop is fine for low-risk work; for actions you cannot undo, you want a person in the loop, before the action runs.
Why bother? Agents make mistakes, and they can be manipulated. OWASP's Top 10 for LLM Applications (2025) lists Excessive Agency as a vulnerability, with "excessive autonomy" as one root cause, and recommends human-in-the-loop control "to require a human to approve high-impact actions before they are taken" (OWASP LLM06:2025). The Model Context Protocol specification makes the same point for tools: "there SHOULD always be a human in the loop with the ability to deny tool invocations" (MCP specification, Tools).
Which agent actions should require human approval?
Not every tool call needs a human. If you ask for approval on everything, reviewers start clicking "approve" without reading, which is worse than no review. Sort the agent's tools into tiers first:
| Tier | Examples | Suggested control |
|---|---|---|
| Read-only | Search a knowledge base, read an order, query a report | No approval; read-only credentials and logging |
| Reversible, internal | Create a draft, add an internal note, open a ticket | Usually no approval; easy undo and an audit log |
| Changes business records | Update a credit limit, change an order status, edit a CRM field | Approval, with the old and new value shown |
| External or irreversible | Send an email or message to a customer, pay or refund, delete data, deploy | Always approval; consider two approvers for large amounts |
| Out of scope | Anything the use case does not need | Do not give the agent this tool at all |
The last row matters most. OWASP's first mitigations are to minimise the tools an agent can call, minimise what each tool can do and minimise its permissions, before you even get to approval steps (OWASP LLM06:2025). An approval step on a tool that should not exist is a weak control.
Which AI platforms support human approval before sensitive actions?
Most serious agent platforms now have a first-class way to pause before a tool call:
-
LangGraph:
interrupt(), with a checkpointer, thenCommand(resume=...)on the samethread_id -
LangChain:
HumanInTheLoopMiddleware - n8n: human review on AI Agent tools, via Slack, Teams, Gmail, WhatsApp and more
-
CrewAI:
@human_feedbackin Flows -
OpenAI Agents SDK:
needs_approval -
Microsoft Agent Framework:
ApprovalRequiredAIFunction -
Google ADK:
require_confirmation
The platform is the easy part. The design work is deciding which actions need approval, showing the reviewer the real parameters, and making sure the write cannot happen without that approval.
How do I add an approval step in LangGraph?
Call interrupt() in a node or tool before the risky action, compile the graph with a checkpointer, run it with a thread_id, show the interrupt payload to a reviewer, and resume with Command(resume=decision) on the same thread_id. Put the actual write after the interrupt, ideally in its own node.
The script below uses a fake ERP record so you can see the pause without an API key. In a real agent, an LLM would draft the proposal.
from typing import Literal, Optional, TypedDict
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import END, START, StateGraph
from langgraph.types import Command, interrupt
# A fake "ERP" table. In real life this is your ERP/CRM API or database.
CUSTOMERS = {"C-1001": {"name": "Asha Traders", "credit_limit": 50000}}
AUDIT_LOG = []
class State(TypedDict):
request: str
customer_id: str
proposed_limit: int
decision: Optional[dict]
result: Optional[str]
def propose(state: State):
# An LLM would read the request and draft this change.
return {"customer_id": "C-1001", "proposed_limit": 80000}
def human_review(state: State) -> Command[Literal["apply_change", "cancelled"]]:
current = CUSTOMERS[state["customer_id"]]["credit_limit"]
# Pause here. Nothing has been written yet.
decision = interrupt({
"action": "update_credit_limit",
"customer_id": state["customer_id"],
"current_limit": current,
"proposed_limit": state["proposed_limit"],
"options": ["approve", "edit", "reject"],
})
if decision.get("type") == "approve":
return Command(goto="apply_change", update={"decision": decision})
if decision.get("type") == "edit":
return Command(goto="apply_change",
update={"decision": decision,
"proposed_limit": int(decision["new_limit"])})
return Command(goto="cancelled", update={"decision": decision})
def apply_change(state: State):
# The side effect runs only after approval, in its own node.
# Setting a value (not adding to it) is idempotent, so a retry is safe.
CUSTOMERS[state["customer_id"]]["credit_limit"] = state["proposed_limit"]
AUDIT_LOG.append({"customer": state["customer_id"],
"new_limit": state["proposed_limit"],
"approved_by": state["decision"].get("reviewer")})
return {"result": f"Credit limit set to {state['proposed_limit']}"}
def cancelled(state: State):
reason = state["decision"].get("reason", "no reason given")
return {"result": f"Change rejected: {reason}"}
builder = StateGraph(State)
builder.add_node("propose", propose)
builder.add_node("human_review", human_review)
builder.add_node("apply_change", apply_change)
builder.add_node("cancelled", cancelled)
builder.add_edge(START, "propose")
builder.add_edge("propose", "human_review")
builder.add_edge("apply_change", END)
builder.add_edge("cancelled", END)
graph = builder.compile(checkpointer=InMemorySaver()) # use a database checkpointer in production
def run(thread_id: str, resume_value: dict):
config = {"configurable": {"thread_id": thread_id}}
first = graph.invoke({"request": "Raise Asha Traders' credit limit to 80k"}, config)
print("Paused for review:", first["__interrupt__"][0].value)
print("ERP before decision:", CUSTOMERS["C-1001"]["credit_limit"])
final = graph.invoke(Command(resume=resume_value), config)
print("Result:", final["result"])
print("ERP after decision:", CUSTOMERS["C-1001"]["credit_limit"], "\n")
if __name__ == "__main__":
run("ticket-1", {"type": "reject", "reason": "Needs finance sign-off"})
run("ticket-2", {"type": "edit", "new_limit": 65000, "reviewer": "finance@company"})
print("Audit log:", AUDIT_LOG)
A copy with tests lives in the human-approval example on GitHub (standard library and LangGraph).
Output on our machine:
Paused for review: {'action': 'update_credit_limit', 'customer_id': 'C-1001', 'current_limit': 50000, 'proposed_limit': 80000, 'options': ['approve', 'edit', 'reject']}
ERP before decision: 50000
Result: Change rejected: Needs finance sign-off
ERP after decision: 50000
Paused for review: {'action': 'update_credit_limit', 'customer_id': 'C-1001', 'current_limit': 50000, 'proposed_limit': 80000, 'options': ['approve', 'edit', 'reject']}
ERP before decision: 50000
Result: Credit limit set to 65000
ERP after decision: 65000
Audit log: [{'customer': 'C-1001', 'new_limit': 65000, 'approved_by': 'finance@company'}]
What to notice:
-
The pause happens before the write. The ERP value is unchanged while the run waits, and a rejected run never reaches
apply_change. - The reviewer sees the current and the proposed value, not a vague "the agent wants to update a customer".
-
The write lives in its own node, after the interrupt. LangGraph's docs explain that when you resume, the node that called
interrupt()runs again from the beginning, so any code before theinterruptruns twice. They recommend placing side effects after the interrupt or in a separate node, and keeping them idempotent (LangGraph interrupts). -
thread_idis the bookmark. Resume with the samethread_idyou started with.InMemorySaverkeeps checkpoints in RAM and loses them on restart, so production systems use a persistent checkpointer such as PostgreSQL (LangGraph persistence).
If you are using LangChain's create_agent, you do not need to write the review node yourself: HumanInTheLoopMiddleware lets you list which tools interrupt and which decisions are allowed for each (LangChain docs).
Can n8n wait for human approval before an AI agent updates a business system?
Yes. n8n is popular for this because the approval request can go wherever your team already works. The setup in n8n's docs is short (n8n human-in-the-loop for tools):
- Build an AI Agent node with its tools, for example an ERPNext node that can retrieve and update documents. n8n's ERPNext node can be used as an AI tool and supports create, retrieve, update and delete operations on documents (n8n ERPNext node).
- Open the AI Agent's Tools panel, add a Human review step and choose the channel (Slack, Teams, Gmail, WhatsApp Business Cloud, Telegram, n8n Chat and others).
- Connect only the risky tools, such as "Update a document", to the human review step. Leave read tools such as "Retrieve a document" connected directly.
- Write the reviewer message with the
$tool.nameand$tool.parametersvariables so the approver sees exactly which tool and values the agent chose. - Tell the agent in its system prompt which tools need approval and what to do when a request is denied. n8n's docs flag this as required so the agent handles rejections gracefully.
For approvals that are not tied to a single tool call (for example, "approve this weekly purchase plan"), n8n's Wait node can pause a whole workflow until a webhook call or form submission arrives, with an optional time limit (n8n Wait node).
How can I use n8n or LangGraph for an agent that queries live ERP data?
A common real-world request is "an agent that answers questions from our live ERP and can fix records". A safe design splits it in two:
- Read path: tools that run fixed, parameterised queries (for example "get open orders for customer X") with a read-only ERP user. No approval needed, but log every call. Avoid a free-form "run any SQL" tool; OWASP's example of excessive permissions is exactly a read tool whose database identity can also update and delete (OWASP LLM06:2025).
- Write path: a small number of narrow tools ("set credit limit", "change order status") using a separate identity, each behind an approval step that shows the old value, the new value and why.
In n8n, that is the ERPNext (or HTTP Request) node for reads plus a human-reviewed tool for writes. In LangGraph, it is read tools bound to the model and write tools that call interrupt() before they act. Either way, the ERP's own permissions should block a write that did not go through approval; never rely on the model to decide what it is allowed to do.
What makes an approval step actually safe?
- Enforce it outside the model. The approval check belongs in code or in the target system, not in a prompt that says "always ask first".
- Show the reviewer real, specific parameters: who, what, old value, new value, amount, recipient.
- Re-check after a long pause, because the world may have changed.
- Make writes idempotent (set a value, use an idempotency key) so a retry after approval cannot apply the change twice.
- Record who approved what and when.
- Handle "no answer" by expiring the request, not auto-approving.
- Keep approvals rare enough to be read.
- Keep the review channel trusted. Anyone who can answer the approval message can approve the action.
What are common human-in-the-loop mistakes?
- Putting
interrupt()after the write, or doing the write in the same node before the pause. - Using an in-memory checkpointer in production and losing every pending approval on restart.
- Giving the agent a powerful general tool (shell, raw SQL, "send any email") and hoping approval catches misuse.
- Approval messages that say "Approve action?" with no details.
- Treating a rejection as an error, so the agent retries the same action instead of explaining or asking what to change.
- Letting the same person request and approve high-value changes.
The full guide, with an FAQ, is on Datamarcos Guides. More free guides on agentic AI, GenAI and data engineering are on the Datamarcos guides hub.
Sources (fetched 27 November 2026, HTTP 200; code re-run 29 November 2026)
- OWASP LLM06:2025, Excessive Agency: https://genai.owasp.org/llmrisk/llm062025-excessive-agency/
- Model Context Protocol specification, Tools: https://modelcontextprotocol.io/specification/2026-07-28/server/tools
- LangGraph interrupts: https://docs.langchain.com/oss/python/langgraph/interrupts
- LangGraph persistence: https://docs.langchain.com/oss/python/langgraph/persistence
- LangChain human-in-the-loop: https://docs.langchain.com/oss/python/langchain/human-in-the-loop
- n8n human-in-the-loop for tools: https://docs.n8n.io/build/integrate-ai/ai-examples/human-in-the-loop-for-tools
- n8n ERPNext node: https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.erpnext
- n8n Wait node: https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.wait
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.