DEV Community

Belal Shafiq
Belal Shafiq

Posted on Originally published at agenttrafficcop.com

LangGraph Tool Approval Before Execution: Human-in-the-Loop

LangGraph Tool Approval Before Execution: Human-in-the-Loop

A LangGraph interrupt() can pause a workflow for a person. It does not, by itself, prove that the person approved the action the graph is about to run.

That distinction matters when a graph pauses on a risky or repeated tool call. While the run is waiting, its state, target, permissions, or the reason for the pause can change. If your resume handler treats “the graph resumed” as “the old action is authorized,” you can execute something different from what the reviewer saw.

This guide shows a safer human-in-the-loop pattern for a specific case: a guarded LangGraph node trips a repeated-action / cycle / step-limit rule and needs an operator review before that node can run again. It is not a blanket approval prompt for every tool call. The example uses AgentTrafficCop’s LangGraph adapter, a durable SQLite checkpointer, and a harmless placeholder action. No model provider or real external tool is called.

The short answer

Before a protected side effect runs after a pause:

  1. Persist the graph with a durable checkpointer and resume the same thread.
  2. Bind the review to a stable run ID and the exact action inputs—not just a node name.
  3. Require an authenticated reviewer decision for that action.
  4. On resume, reject a changed or expired approval and re-check current policy immediately before execution.
  5. Re-authorize the real operation in your application too. A loop approval is not an access-control decision.

Why a resume is not authorization

LangGraph interrupts are a control-flow mechanism: they let a graph pause and later continue from a checkpoint. The resume value is supplied by the caller of the graph. If code accepts any truthy value—or trusts a client-supplied approved: true—as permission, the caller can turn a workflow signal into an authorization bypass.

There is a second problem: staleness. Suppose a reviewer sees a request to send a report to team@example.com. While the graph is paused, the recipient changes, the report changes, or the user loses permission to send it. Resuming with the old review ID must not authorize the new action.

A sound approval check therefore needs to answer more than “did this thread resume?” It needs to verify that:

  • the reviewer was authorized and actually approved;
  • the approval is still valid and has not already been used;
  • it belongs to this run and this exact action;
  • the relevant detector / workflow state has not changed; and
  • current application authorization still permits the operation.

Put the check on the execution path

Wrap the node that can perform the side effect, rather than a nearby model node and hoping every path passes through it. Derive the session ID from trusted run state. Build the payload from the inputs the tool will actually use, including meaningful fields such as the operation, destination, and resource identifier.

Here is the core shape with the AgentTrafficCop LangGraph adapter:

from agenttrafficcop.langgraph import guarded_node

protected_send = guarded_node(
    send_report,  # the node that would perform the side effect
    guard=guard,  # an open AgentTrafficCop Guard
    sender="report-workflow",
    recipient="send-report-tool",
    session_id=lambda state: state["run_id"],
    payload=lambda state: {
        "tool": "send_report",
        "recipient": state["recipient"],
        "report_id": state["report_id"],
        "report_version": state["report_version"],
    },
    review_on_trip=True,
)

builder.add_node("send_report", protected_send)
graph = builder.compile(checkpointer=durable_checkpointer)
Enter fullscreen mode Exit fullscreen mode

This is an integration pattern, not a complete standalone application: guard, send_report, the graph state, and durable_checkpointer come from your app. The important part is that the payload describes the exact operation and is resolved again from the resumed state. If those values change, the pending review must not silently carry over.

review_on_trip=True is for a guard trip; it does not force a human to approve every successful tool call. The wrapper protects only the node you explicitly wrap. It does not automatically intercept every model request, tool, subgraph, background worker, or direct call elsewhere in your program.

Run the safe end-to-end example

The repository includes a live-service example that exercises the pause, dashboard review, durable checkpoint, resume verification, and fresh guard check without calling an LLM or performing a real send. From a clone of the repository:

python -m pip install 'agenttrafficcop[langgraph]==2.7.0' \
  'langgraph-checkpoint-sqlite>=3.1.3,<3.2.0'

export ATC_URL='https://api.agenttrafficcop.com'
export ATC_API_KEY='your-server-issued-key'
python examples/langgraph_native_review.py
Enter fullscreen mode Exit fullscreen mode

The example stores checkpoints in atc-langgraph-checkpoints.sqlite. It repeats one static, harmless placeholder action until the detector trips. When it pauses, it prints a run ID and review ID. Review the request in the authenticated AgentTrafficCop dashboard; the example then resumes and relies on the SDK/backend verification—not the Enter key—to decide whether the protected node may run.

If the process exits while paused, restart with the same run ID and checkpoint database, and pass the saved review ID:

python examples/langgraph_native_review.py \
  --run-id "$ATC_RUN_ID" \
  --resume-review-id "$ATC_REVIEW_ID"
Enter fullscreen mode Exit fullscreen mode

The example is deliberately safe: its node prints that a placeholder action was approved; it does not send an email, call a payment API, or invoke a model. Do not replace the placeholder with a real side effect until you have bound the review to the real inputs and added your own authorization and recovery controls. See the complete example source and LangGraph review walkthrough.

What the resume path must verify

With review_on_trip=True, the adapter does not treat the resume command as proof of approval. On resume it verifies the review ID with the review verifier, checks the current action against the approved action, and performs a fresh AgentTrafficCop check immediately before invoking the wrapped node. The built-in verifier is used by default; a custom review_approval callback is optional and must fail closed.

The interrupt payload is intentionally minimal: it contains a review type, session ID, opaque review ID, and safe error code—not the full graph state, prompts, tool results, or exception text. Keep API keys and other secrets out of graph state and interrupt payloads regardless.

A database-backed checkpointer matters because a process-local or in-memory saver will not provide restart durability. Persist and reuse the same LangGraph thread_id (the example uses the run ID), checkpoint store, and review ID. Protect the checkpoint database: it can contain application state even though the adapter's interrupt event is minimal.

The application still owns authorization

A valid loop review is not a general-purpose security approval. It does not prove the user is allowed to access a tenant, send to a recipient, issue a refund, or mutate a resource. Re-check those rules using trusted identity and current application data immediately before the side effect.

Also consider time-of-check/time-of-use races. If the destination or resource can change between the final check and the external request, bind and validate it as close to the operation as possible. For high-impact actions, use an idempotency key, transaction, or durable operation record so a process restart or ambiguous network failure cannot accidentally run the side effect twice.

Approval should be understandable to the person making it. Show the actual operation and target in an authenticated review UI; do not ask someone to approve an opaque ID alone. If you minimize or hash payloads for privacy, make sure the reviewer still has enough trusted context to make a meaningful decision. A hash can bind data; it cannot explain the data to a human.

Common failure modes

  • Using MemorySaver in production: the pause may not survive a process restart. Use a durable saver and test restart/resume.
  • Approving a run instead of an action: a run can contain many actions. Bind approval narrowly to one action and the relevant state.
  • Trusting Command(resume=...): a resume value is input to the graph, not an authenticated reviewer decision.
  • Reusing an old review ID: approvals can expire, be rejected, be consumed, or become stale. On failure, stop and request a fresh review; do not “fix” it by skipping verification.
  • Checking only the node name: two calls to the same node can target different recipients, accounts, files, or amounts. Include the business fields that distinguish the action.
  • Wrapping the wrong boundary: wrapping a planner does not protect an unwrapped tool node. Trace every route to the side effect and test rejection before execution.
  • Treating loop detection as safety validation: a repeated-action guard can identify a pattern; it does not validate the meaning or legitimacy of a tool call.

When this pattern fits—and when it does not

Use this pattern when a protected node is blocked by a repeated-action, cycle, or step-limit guard and an operator needs to review a narrowly scoped continuation. If your requirement is “a human must approve every transfer” or “every email must be approved,” implement that explicit business approval policy at the tool boundary; do not rely on review_on_trip to prompt on calls that pass the guard.

For a production rollout, test at least these cases: normal approved execution; guard trip with no side effect before review; rejected review; forged, expired, or reused review ID; changed action while paused; changed detector state; restart from the durable checkpoint; and application authorization revoked before resume. In every failure case, assert that the external operation did not run.

Takeaway

A LangGraph interrupt gives you a pause point. Safe execution after that pause requires a durable checkpoint, a real reviewer decision tied to the exact action, fresh checks on resume, and application-owned authorization at the side-effect boundary. Treat resume as control flow—not as permission.

If you are wiring this into an existing graph, start with the AgentTrafficCop LangGraph guide and adapt the safe example to your own action boundary.

Top comments (0)