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 Checkpoint
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    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 Checkpoint
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    Language
    Theme
    PythonlanggraphgraphstateStateGraphset_node_defaults
    Methodā—Since v1.2

    set_node_defaults

    Copy
    set_node_defaults(
      self,
      *,
      retry_policy: RetryPolicy | Sequence[RetryPolicy] | None =
    View source on GitHub
    None
    ,
    cache_policy
    :
    CachePolicy
    |
    None
    =
    None
    ,
    error_handler
    :
    StateNode
    [
    Any
    ,
    ContextT
    ]
    |
    None
    =
    None
    ,
    timeout
    :
    float
    |
    timedelta
    |
    TimeoutPolicy
    |
    None
    =
    None
    )
    ->
    Self

    Parameters

    NameTypeDescription
    retry_policyRetryPolicy | Sequence[RetryPolicy] | None
    Default:None

    Default retry policy for nodes that don't specify their own via add_node(..., retry_policy=...). Also applies to error-handler nodes.

    cache_policyCachePolicy | None
    Default:None

    Default cache policy for nodes that don't specify their own via add_node(..., cache_policy=...). Does not apply to error-handler nodes.

    error_handlerStateNode[Any, ContextT] | None
    Default:None
    timeoutfloat | timedelta | TimeoutPolicy | None
    Default:None

    Set default node policies that apply to every node in this graph.

    Per-node values passed to add_node always take precedence over these defaults. Defaults are applied at compile() time. Policies set here are not inherited by subgraphs.

    retry_policy and timeout defaults apply to all nodes, including error-handler nodes. cache_policy and error_handler defaults only apply to regular nodes -- caching error-handler results is unsafe, and handlers must never catch themselves.

    Example:

    graph = (
        StateGraph(State)
        .set_node_defaults(
            retry_policy=RetryPolicy(max_attempts=3),
            error_handler=my_fallback_handler,
        )
        .add_node("a", node_a)
        .add_node("b", node_b, retry_policy=custom_retry)  # overrides default
        .add_edge(START, "a")
        .compile()
    )

    Default error handler invoked when any regular node raises and does not have its own error_handler set via add_node. The handler is not invoked when an error-handler node itself raises -- handler failures fail the run.

    Default timeout policy for nodes that don't specify their own via add_node(..., timeout=...). Also applies to error-handler nodes. Accepts a TimeoutPolicy, a number of seconds (float), or a timedelta.