LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Graphs
    • Functional API
    • Pregel
    • Checkpointing
    • Storage
    • Caching
    • Types
    • Runtime
    • Config
    • Errors
    • Constants
    • Channels
    • Agents
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewGraphsFunctional APIPregelCheckpointingStorageCachingTypesRuntimeConfigErrorsConstantsChannelsAgents
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    Language
    Theme
    Pythonlanggraphtypesinterrupt
    Function●Since v0.2

    interrupt

    Interrupt the graph with a resumable exception from within a node.

    The interrupt function enables human-in-the-loop workflows by pausing graph execution and surfacing a value to the client. This value can communicate context or request input required to resume execution.

    In a given node, the first invocation of this function raises a GraphInterrupt exception, halting execution. The provided value is included with the exception and sent to the client executing the graph.

    A client resuming the graph must use the Command primitive to specify a value for the interrupt and continue execution. The graph resumes from the start of the node, re-executing all logic.

    If a node contains multiple interrupt calls, LangGraph matches resume values to interrupts based on their order in the node. This list of resume values is scoped to the specific task executing the node and is not shared across tasks.

    To use an interrupt, you must enable a checkpointer, as the feature relies on persisting the graph state.

    Example
    import uuid
    from typing import Optional
    from typing_extensions import TypedDict
    
    from langgraph.checkpoint.memory import InMemorySaver
    from langgraph.constants import START
    from langgraph.graph import StateGraph
    from langgraph.types import interrupt, Command
    
    class State(TypedDict):
        """The graph state."""
    
        foo: str
        human_value: Optional[str]
        """Human value will be updated using an interrupt."""
    
    def node(state: State):
        answer = interrupt(
            # This value will be sent to the client
            # as part of the interrupt information.
            "what is your age?"
        )
        print(f"> Received an input from the interrupt: {answer}")
        return {"human_value": answer}
    
    builder = StateGraph(State)
    builder.add_node("node", node)
    builder.add_edge(START, "node")
    
    # A checkpointer must be enabled for interrupts to work!
    checkpointer = InMemorySaver()
    graph = builder.compile(checkpointer=checkpointer)
    
    config = {
        "configurable": {
            "thread_id": uuid.uuid4(),
        }
    }
    
    for chunk in graph.stream({"foo": "abc"}, config):
        print(chunk)
    
    # > {'__interrupt__': (Interrupt(value='what is your age?', id='45fda8478b2ef754419799e10992af06'),)}
    
    command = Command(resume="some input from a human!!!")
    
    for chunk in graph.stream(Command(resume="some input from a human!!!"), config):
        print(chunk)
    
    # > Received an input from the interrupt: some input from a human!!!
    # > {'node': {'human_value': 'some input from a human!!!'}}
    Copy
    interrupt(
        value: Any,
    ) -> Any

    Used in Docs

    • Build a custom SQL agent
    • Evaluate a complex agent
    • Functional API overview
    • Graph API overview
    • Human-in-the-loop

    Parameters

    NameTypeDescription
    value*Any

    The value to surface to the client when the graph is interrupted.

    View source on GitHub