INVOKE THIS SKILL when implementing human-in-the-loop patterns, pausing for approval, or handling errors in LangGraph. Covers interrupt(), Command(resume=...), approval/validation workflows, and the 4-tier error handling strategy.
INVOKE THIS SKILL when implementing human-in-the-loop patterns, pausing for approval, or handling errors in LangGraph. Covers interrupt(), Command(resume=...), approval/validation workflows, and the 4-tier error handling strategy.
LangGraph's human-in-the-loop patterns let you pause graph execution, surface data to users, and resume with their input:
interrupt(value) — pauses execution, surfaces a value to the caller
Command(resume=value) — resumes execution, providing the value back to interrupt()
Checkpointer — required to save state while paused
Thread ID — required to identify which paused execution to resume
Requirements
Three things are required for interrupts to work:
Checkpointer — compile with checkpointer=InMemorySaver() (dev) or PostgresSaver (prod)
Thread ID — pass {"configurable": {"thread_id": "..."}} to every invoke/stream call
JSON-serializable payload — the value passed to interrupt() must be JSON-serializable
Basic Interrupt + Resume
interrupt(value) pauses the graph. The value surfaces in the result under __interrupt__. Command(resume=value) resumes — the resume value becomes the return value of interrupt().
Critical: when the graph resumes, the node restarts from the beginning — all code before interrupt() re-runs.
Pause execution for human review and resume with Command.
Pause execution for human review and resume with Command.
Interrupt for human review, then route to send or end based on the decision.
Interrupt for human review, then route to send or end based on the decision.
Validate human input in a loop, re-prompting until valid.
Validate human input in a loop, re-prompting until valid.
Resume multiple parallel interrupts by mapping interrupt IDs to values.
Resume multiple parallel interrupts by mapping interrupt IDs to values.
Idempotent operations before interrupt vs non-idempotent (wrong).
Idempotent operations before interrupt vs non-idempotent (wrong).
Checkpointer required for interrupt functionality.
Checkpointer required for interrupt functionality.
Use Command to resume from an interrupt (regular dict restarts graph).
Use Command to resume from an interrupt (regular object restarts graph).
### What You Should NOT Do
from langgraph.types import interrupt, Command
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import StateGraph, START, END
from typing_extensions import TypedDict
classState(TypedDict):
approved: booldefapproval_node(state: State):
# Pause and ask for approval
approved = interrupt("Do you approve this action?")
# When resumed, Command(resume=...) returns that value herereturn {"approved": approved}
checkpointer = InMemorySaver()
graph = (
StateGraph(State)
.add_node("approval", approval_node)
.add_edge(START, "approval")
.add_edge("approval", END)
.compile(checkpointer=checkpointer)
)
config = {"configurable": {"thread_id": "thread-1"}}
# Initial run — hits interrupt and pauses
result = graph.invoke({"approved": False}, config)
print(result["__interrupt__"])
# [Interrupt(value='Do you approve this action?')]# Resume with the human's response
result = graph.invoke(Command(resume=True), config)
print(result["approved"]) # True
import { interrupt, Command, MemorySaver, StateGraph, StateSchema, START, END } from"@langchain/langgraph";
import { z } from"zod";
constState = newStateSchema({
approved: z.boolean().default(false),
});
constapprovalNode = async (state: typeofState.State) => {
// Pause and ask for approvalconst approved = interrupt("Do you approve this action?");
// When resumed, Command({ resume }) returns that value herereturn { approved };
};
const checkpointer = newMemorySaver();
const graph = newStateGraph(State)
.addNode("approval", approvalNode)
.addEdge(START, "approval")
.addEdge("approval", END)
.compile({ checkpointer });
const config = { configurable: { thread_id: "thread-1" } };
// Initial run — hits interrupt and pauseslet result = await graph.invoke({ approved: false }, config);
console.log(result.__interrupt__);
// [{ value: 'Do you approve this action?', ... }]// Resume with the human's response
result = await graph.invoke(newCommand({ resume: true }), config);
console.log(result.approved); // true
Approval Workflow
A common pattern: interrupt to show a draft, then route based on the human's decision.
from langgraph.types import interrupt, Command
from langgraph.graph import StateGraph, START, END
from typing importLiteralfrom typing_extensions import TypedDict
classEmailAgentState(TypedDict):
email_content: str
draft_response: str
classification: dictdefhuman_review(state: EmailAgentState) -> Command[Literal["send_reply", "__end__"]]:
"""Pause for human review using interrupt and route based on decision."""
classification = state.get("classification", {})
# interrupt() must come first — any code before it will re-run on resume
human_decision = interrupt({
"email_id": state.get("email_content", ""),
"draft_response": state.get("draft_response", ""),
"urgency": classification.get("urgency"),
"action": "Please review and approve/edit this response"
})
# Process the human's decisionif human_decision.get("approved"):
return Command(
update={"draft_response": human_decision.get("edited_response", state.get("draft_response", ""))},
goto="send_reply"
)
else:
# Rejection — human will handle directlyreturn Command(update={}, goto=END)
import { interrupt, Command, END, GraphNode } from"@langchain/langgraph";
consthumanReview: GraphNode<typeofEmailAgentState> = async (state) => {
const classification = state.classification!;
// interrupt() must come first — any code before it will re-run on resumeconst humanDecision = interrupt({
emailId: state.emailContent,
draftResponse: state.responseText,
urgency: classification.urgency,
action: "Please review and approve/edit this response",
});
// Process the human's decisionif (humanDecision.approved) {
returnnewCommand({
update: { responseText: humanDecision.editedResponse || state.responseText },
goto: "sendReply",
});
} else {
returnnewCommand({ update: {}, goto: END });
}
};
Validation Loop
Use interrupt() in a loop to validate human input and re-prompt if invalid.
from langgraph.types import interrupt
defget_age_node(state):
prompt = "What is your age?"whileTrue:
answer = interrupt(prompt)
# Validate the inputifisinstance(answer, int) and answer > 0:
breakelse:
# Invalid input — ask again with a more specific prompt
prompt = f"'{answer}' is not a valid age. Please enter a positive number."return {"age": answer}
Each Command(resume=...) call provides the next answer. If invalid, the loop re-interrupts with a clearer message.
config = {"configurable": {"thread_id": "form-1"}}
first = graph.invoke({"age": None}, config)
# __interrupt__: "What is your age?"
retry = graph.invoke(Command(resume="thirty"), config)
# __interrupt__: "'thirty' is not a valid age..."
final = graph.invoke(Command(resume=30), config)
print(final["age"]) # 30
import { interrupt } from"@langchain/langgraph";
constgetAgeNode = (state: typeofState.State) => {
let prompt = "What is your age?";
while (true) {
const answer = interrupt(prompt);
// Validate the inputif (typeof answer === "number" && answer > 0) {
return { age: answer };
} else {
// Invalid input — ask again with a more specific prompt
prompt = `'${answer}' is not a valid age. Please enter a positive number.`;
}
}
};
Multiple Interrupts
When parallel branches each call interrupt(), resume all of them in a single invocation by mapping each interrupt ID to its resume value.
from typing import Annotated, TypedDict
import operator
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import START, END, StateGraph
from langgraph.types import Command, interrupt
classState(TypedDict):
vals: Annotated[list[str], operator.add]
defnode_a(state):
answer = interrupt("question_a")
return {"vals": [f"a:{answer}"]}
defnode_b(state):
answer = interrupt("question_b")
return {"vals": [f"b:{answer}"]}
graph = (
StateGraph(State)
.add_node("a", node_a)
.add_node("b", node_b)
.add_edge(START, "a")
.add_edge(START, "b")
.add_edge("a", END)
.add_edge("b", END)
.compile(checkpointer=InMemorySaver())
)
config = {"configurable": {"thread_id": "1"}}
# Both parallel nodes hit interrupt() and pause
result = graph.invoke({"vals": []}, config)
# result["__interrupt__"] contains both Interrupt objects with IDs# Resume all pending interrupts at once using a map of id -> value
resume_map = {
i.id: f"answer for {i.value}"for i in result["__interrupt__"]
}
result = graph.invoke(Command(resume=resume_map), config)
# result["vals"] = ["a:answer for question_a", "b:answer for question_b"]
User-fixable errors use interrupt() to pause and collect missing data — that's the pattern covered by this skill. For the full 4-tier error handling strategy (RetryPolicy, Command error loops, etc.), see the fundamentals skill.
Side Effects Before Interrupt Must Be Idempotent
When the graph resumes, the node restarts from the beginning — ALL code before interrupt() re-runs. In subgraphs, BOTH the parent node and the subgraph node re-execute.
Do:
Use upsert (not insert) operations before interrupt()
Use check-before-create patterns
Place side effects afterinterrupt() when possible
Separate side effects into their own nodes
Don't:
Create new records before interrupt() — duplicates on each resume
Append to lists before interrupt() — duplicate entries on each resume
# GOOD: Upsert is idempotent — safe before interruptdefnode_a(state: State):
db.upsert_user(user_id=state["user_id"], status="pending_approval")
approved = interrupt("Approve this change?")
return {"approved": approved}
# GOOD: Side effect AFTER interrupt — only runs oncedefnode_a(state: State):
approved = interrupt("Approve this change?")
if approved:
db.create_audit_log(user_id=state["user_id"], action="approved")
return {"approved": approved}
# BAD: Insert creates duplicates on each resume!defnode_a(state: State):
audit_id = db.create_audit_log({ # Runs again on resume!"user_id": state["user_id"],
"action": "pending_approval",
})
approved = interrupt("Approve this change?")
return {"approved": approved}
// GOOD: Upsert is idempotent — safe before interruptconstnodeA = async (state: typeofState.State) => {
await db.upsertUser({ userId: state.userId, status: "pending_approval" });
const approved = interrupt("Approve this change?");
return { approved };
};
// GOOD: Side effect AFTER interrupt — only runs onceconstnodeA = async (state: typeofState.State) => {
const approved = interrupt("Approve this change?");
if (approved) {
await db.createAuditLog({ userId: state.userId, action: "approved" });
}
return { approved };
};
// BAD: Insert creates duplicates on each resume!constnodeA = async (state: typeofState.State) => {
await db.createAuditLog({ // Runs again on resume!userId: state.userId,
action: "pending_approval",
});
const approved = interrupt("Approve this change?");
return { approved };
};
Subgraph re-execution on resume
When a subgraph contains an interrupt(), resuming re-executes BOTH the parent node (that invoked the subgraph) AND the subgraph node (that called interrupt()):
defnode_in_parent_graph(state: State):
some_code() # <-- Re-executes on resume
subgraph_result = subgraph.invoke(some_input)
# ...defnode_in_subgraph(state: State):
some_other_code() # <-- Also re-executes on resume
result = interrupt("What's your name?")
# ...
asyncfunctionnodeInParentGraph(state: State) {
someCode(); // <-- Re-executes on resumeconst subgraphResult = await subgraph.invoke(someInput);
// ...
}
asyncfunctionnodeInSubgraph(state: State) {
someOtherCode(); // <-- Also re-executes on resumeconst result = interrupt("What's your name?");
// ...
}
Command(resume) Warning
Command(resume=...) is the only Command pattern intended as input to invoke()/stream(). Do NOT pass Command(update=...) as input — it resumes from the latest checkpoint and the graph appears stuck. See the fundamentals skill for the full antipattern explanation.