Build a Privacy-Aware LangGraph Agent with Tool Approval and Recovery
A practical pattern for using LangGraph human review, checkpointing, bounded runs, and credential-safe tools in an agent that handles sensitive data.
Summary · TL;DR
Use LangGraph’s human-in-the-loop middleware to pause sensitive tool calls, review or reject them, and resume from a checkpoint. Pair that workflow with strict tool boundaries, credential isolation, and an execution limit.
Key Takeaways
- Keep credentials inside tool implementations; pass the model only the minimum arguments it needs.
- Require human review for sensitive writes or queries, while allowing safe reads to proceed.
- Use a persistent checkpointer and a stable thread ID to resume interrupted work.
- Bound graph execution and make tools idempotent or independently safe to retry.
- Treat checkpointed state and interrupt payloads as sensitive data.
On this page (5)
A privacy-aware agent should not rely on the model to decide whether a tool call is safe. Keep credentials outside the conversation, constrain what each tool can do, and pause sensitive actions for human review. LangGraph’s human-in-the-loop middleware provides the pause-and-resume mechanism; your application still has to define data handling, authorization, and execution limits.
This guide builds a small pattern for an agent that can read customer records and request a database change. The code is illustrative, not tested here. Check package versions and tool signatures against your environment before deployment.
1. Separate model context from credentials
Do not place passwords, API keys, session cookies, or unrestricted database credentials in prompts or tool arguments. Instead, give tools narrow operations and have them obtain credentials from your application’s secret-management mechanism at execution time. The model should see only the data needed to choose an action.
For example, prefer a tool such as find_customer_record(customer_id) over a general-purpose tool that accepts arbitrary SQL and connection details. Validate authorization in the tool itself: a user’s request is not proof that they may access the requested record.
Human review is an additional control, not an authorization system. Reviewers should see enough to make a decision, but avoid displaying unnecessary personal data or secrets in review screens and logs.
2. Configure review for sensitive actions
The supplied LangChain human-in-the-loop documentation describes middleware that checks tool calls against a policy. Matching calls can interrupt execution; a checkpointer saves graph state so the run can resume later. The documented decisions include approval, editing arguments, rejection with feedback, and responding to a tool that asks the user a question.
Here is an illustrative configuration. Replace the placeholder tools with implementations that enforce your application’s access rules and input validation.
from langchain.agents import create_agent
from langchain.agents.middleware import HumanInTheLoopMiddleware
from langgraph.checkpoint.memory import InMemorySaver
agent = create_agent(
model="YOUR_CONFIGURED_MODEL",
tools=[read_customer_record, update_customer_record],
middleware=[
HumanInTheLoopMiddleware(
interrupt_on={
"read_customer_record": False,
"update_customer_record": {
"allowed_decisions": ["approve", "edit", "reject"]
},
},
description_prefix="Review requested customer-data change",
),
],
# For production, use a persistent checkpointer appropriate to your stack.
checkpointer=InMemorySaver(),
)
InMemorySaver is suitable for prototyping, not durable recovery across process restarts. The documentation requires a checkpointer for human-review interruptions and names persistent options such as AsyncPostgresSaver and MongoDBSaver. Choose storage with access controls, retention rules, and encryption appropriate to the data you checkpoint. A checkpoint may contain messages and tool arguments, so it can hold sensitive user data even when credentials are excluded.
If only certain calls need review, the documentation also supports a when predicate for conditional interrupts (requires langchain>=1.3.3). For example, you might pause a write outside an approved workspace or a query that is not read-only. Do not treat a string-prefix check as a complete SQL security policy; enforce safe operations at the database and tool layers too.
3. Pause, review, and resume the same run
Use a stable thread ID so the application can associate the pending review with the correct conversation. Protect that identifier and the review interface: possession of a thread ID should not grant permission to approve an action.
from langgraph.types import Command
config = {"configurable": {"thread_id": "conversation-123"}}
result = agent.invoke(
{"messages": [{"role": "user", "content": "Update this customer's address"}]},
config=config,
version="v2",
)
if result.interrupts:
# Present the requested action to an authenticated reviewer.
# Resume only after recording that reviewer's decision.
result = agent.invoke(
Command(resume={"decisions": [{"type": "reject", "message": "Verify the request first."}]}),
config=config,
version="v2",
)
The decision order must match the order of actions in the interrupt request when multiple tool calls are paused. Use reject to deny a side-effecting action. The documentation warns that respond supplies a synthetic tool result; it is for answering an “ask user” style tool, not for denying a write.
4. Bound execution and design for recovery
A review pause does not by itself prevent a model from repeatedly requesting tools. Set a graph recursion limit on invocations and handle the resulting limit error as a controlled stop. The exact limit is workload-dependent; choose one based on the maximum useful sequence of model and tool steps, and test the behavior at the boundary.
config = {
"configurable": {"thread_id": "conversation-123"},
"recursion_limit": 12,
}
This illustrative setting limits graph steps; it is not a guarantee against slow tools, large outputs, or repeated external side effects. Add timeouts to network and database calls, cap tool output, and validate inputs. For retryable operations, use idempotency controls or check current state before applying a change. If a run fails after a tool has succeeded but before the agent records the result, blindly retrying could perform the operation twice.
On recovery, resume the same checkpointed thread only after verifying the pending action and its authorization are still valid. If the user’s permissions or underlying record changed while review was pending, reject or revalidate rather than executing stale arguments.
5. Privacy and failure checklist
Before production, confirm that:
- Tool implementations fetch credentials privately and never return them in tool results or errors.
- Each tool enforces user authorization and accepts only the narrowest useful arguments.
- Checkpoints, interrupt payloads, logs, and reviewer screens have defined access and retention controls.
- A reviewer can identify the target and consequence without seeing unrelated personal data.
- Rejections do not execute the tool, and retries cannot duplicate side effects.
- Runs have step limits, tool timeouts, output limits, and a clear path for reporting interrupted or failed work.
The key design choice is to treat human approval as one checkpoint in a secured workflow—not as a substitute for least privilege, data minimization, or tool-level validation.
FAQ
Does LangGraph human-in-the-loop middleware store the paused agent state?
It uses LangGraph persistence to save state across an interrupt. A checkpointer is required, and production deployments should select persistent storage and apply appropriate access and retention controls.
Should I use the respond decision to reject a sensitive tool call?
No. The documented behavior treats respond as a synthetic successful tool result, intended for cases such as answering an ask-user tool. Use reject to deny a side-effecting action.
How do I keep credentials private in a LangGraph agent?
Keep credentials in the tool’s execution environment or secret-management layer. Do not put them in prompts, model-visible tool arguments, tool results, interrupt messages, or logs.
Does human approval prevent an agent from running indefinitely?
No. Approval middleware handles review of configured tool calls. Add an execution limit, tool timeouts, output limits, and safe retry behavior separately.
Related articles
Guides
Build a Bounded LangGraph Tool-Calling Agent with Human Review
A practical pattern for evaluating a LangGraph tool-calling agent with explicit step limits, human approval for risky actions, and repeatable test cases.
Guides
Build a LangGraph Customer Support Agent with Tool Calling, Human Approval, and Execution Limits
A practical LangGraph pattern for customer-support triage: route requests, call lookup tools, pause refunds for human approval, and bound graph execution.
Guides
LangGraph Tool Calling with Bounded Execution and Failure Recovery
Build a LangGraph production-operations agent that uses tool calling, retry budgets, human approval, and explicit recovery paths instead of unbounded execution.
Guides
Build a Bounded LangGraph Agent for API Incident Diagnosis
Build a LangGraph incident-diagnosis agent that calls read-only diagnostic tools, limits execution, surfaces failures, and pauses before risky actions.