LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-corerunnablesbaseRunnableBinding
    Class●Since v0.1

    RunnableBinding

    Copy
    RunnableBinding(
      self
    ,
    *
    ,
    bound
    :
    Runnable
    [
    Input
    ,
    Output
    ]
    ,
    kwargs
    :
    Mapping
    [
    str
    ,
    Any
    ]
    |
    None
    =
    None
    ,
    config
    :
    RunnableConfig
    |
    None
    =
    None
    ,
    config_factories
    :
    list
    [
    Callable
    [
    [
    RunnableConfig
    ]
    ,
    RunnableConfig
    ]
    ]
    |
    None
    =
    None
    ,
    custom_input_type
    :
    type
    [
    Input
    ]
    |
    BaseModel
    |
    None
    =
    None
    ,
    custom_output_type
    :
    type
    [
    Output
    ]
    |
    BaseModel
    |
    None
    =
    None
    ,
    **
    other_kwargs
    :
    Any
    =
    {
    }
    )

    Bases

    RunnableBindingBase[Input, Output]

    Methods

    method
    bind
    method
    with_config
    method
    with_listeners
    method
    with_types
    method
    with_retry

    Inherited fromRunnableBindingBase

    Attributes

    Abound: Runnable[Input, Output]Akwargs: Mapping[str, Any]
    —

    kwargs to pass to the underlying Runnable when running.

    Aconfig: RunnableConfig | None
    —

    The configuration to use.

    Aconfig_factories: list[Callable[[RunnableConfig], RunnableConfig]]
    —

    The config factories to bind to the underlying Runnable.

    Acustom_input_type: Any | None
    —

    Override the input type of the underlying Runnable with a custom type.

    Acustom_output_type: Any | None
    —

    Override the output type of the underlying Runnable with a custom type.

    Amodel_configAInputType: AnyAOutputType: AnyAconfig_specs: list[ConfigurableFieldSpec]

    Methods

    Mget_nameMget_input_schemaMget_output_schemaMget_graphMis_lc_serializable
    —

    Return True as this class is serializable.

    Inherited fromRunnableSerializable

    Attributes

    Aname: str
    —

    The name of the function.

    Amodel_config

    Methods

    Mto_json
    —

    Convert the graph to a JSON-serializable format.

    Inherited fromSerializable

    Attributes

    Alc_secrets: dict[str, str]
    —

    A map of constructor argument names to secret ids.

    Alc_attributes: dict
    —

    List of attribute names that should be included in the serialized kwargs.

    Amodel_config

    Methods

    Inherited fromRunnable

    Attributes

    Aname: str
    —

    The name of the function.

    AInputType: AnyAOutputType: AnyAinput_schema
    View source on GitHub

    Wrap a Runnable with additional functionality.

    A RunnableBinding can be thought of as a "runnable decorator" that preserves the essential features of Runnable; i.e., batching, streaming, and async support, while adding additional functionality.

    Any class that inherits from Runnable can be bound to a RunnableBinding. Runnables expose a standard set of methods for creating RunnableBindings or sub-classes of RunnableBindings (e.g., RunnableRetry, RunnableWithFallbacks) that add additional functionality.

    These methods include:

    • bind: Bind kwargs to pass to the underlying Runnable when running it.
    • with_config: Bind config to pass to the underlying Runnable when running it.
    • with_listeners: Bind lifecycle listeners to the underlying Runnable.
    • with_types: Override the input and output types of the underlying Runnable.
    • with_retry: Bind a retry policy to the underlying Runnable.
    • with_fallbacks: Bind a fallback policy to the underlying Runnable.

    Example: bind: Bind kwargs to pass to the underlying Runnable when running it.

    # Create a Runnable binding that invokes the chat model with the
    # additional kwarg `stop=['-']` when running it.
    from langchain_openai import ChatOpenAI
    
    model = ChatOpenAI()
    model.invoke('Say "Parrot-MAGIC"', stop=["-"])  # Should return `Parrot`
    # Using it the easy way via `bind` method which returns a new
    # RunnableBinding
    runnable_binding = model.bind(stop=["-"])
    runnable_binding.invoke('Say "Parrot-MAGIC"')  # Should return `Parrot`

    Can also be done by instantiating a RunnableBinding directly (not recommended):

    from langchain_core.runnables import RunnableBinding
    
    runnable_binding = RunnableBinding(
        bound=model,
        kwargs={"stop": ["-"]},  # <-- Note the additional kwargs
    )
    runnable_binding.invoke('Say "Parrot-MAGIC"')  # Should return `Parrot`
    M
    get_lc_namespace
    —

    Get the namespace of the LangChain object.

    Minvoke
    —

    Invoke the retriever to get relevant documents.

    Mainvoke
    —

    Asynchronously invoke the retriever to get relevant documents.

    Mbatch
    Mabatch
    Mbatch_as_completed
    —

    Run invoke in parallel on a list of inputs.

    Mabatch_as_completed
    —

    Run ainvoke in parallel on a list of inputs.

    Mstream
    Mastream
    Mastream_events
    —

    Generate a stream of events.

    Mtransform
    Matransform
    M
    configurable_fields
    Mconfigurable_alternatives
    —

    Configure alternatives for Runnable objects that can be set at runtime.

    M
    is_lc_serializable
    —

    Return True as this class is serializable.

    Mget_lc_namespace
    —

    Get the namespace of the LangChain object.

    Mlc_id
    —

    Return a unique identifier for this class for serialization purposes.

    Mto_json
    —

    Convert the graph to a JSON-serializable format.

    Mto_json_not_implemented
    —

    Serialize a "not implemented" object.

    : type[BaseModel]
    —

    The type of input this Runnable accepts specified as a Pydantic model.

    Aoutput_schema: type[BaseModel]
    —

    Output schema.

    Aconfig_specs: list[ConfigurableFieldSpec]

    Methods

    Mget_nameMget_input_schemaMget_input_jsonschema
    —

    Get a JSON schema that represents the input to the Runnable.

    Mget_output_schemaMget_output_jsonschema
    —

    Get a JSON schema that represents the output of the Runnable.

    Mconfig_schema
    —

    The type of config this Runnable accepts specified as a Pydantic model.

    Mget_config_jsonschema
    —

    Get a JSON schema that represents the config of the Runnable.

    Mget_graphMget_prompts
    —

    Return a list of prompts used by this Runnable.

    Mpipe
    —

    Pipe Runnable objects.

    Mpick
    —

    Pick keys from the output dict of this Runnable.

    Massign
    —

    Merge the Dict input with the output produced by the mapping argument.

    Minvoke
    —

    Invoke the retriever to get relevant documents.

    Mainvoke
    —

    Asynchronously invoke the retriever to get relevant documents.

    MbatchMbatch_as_completed
    —

    Run invoke in parallel on a list of inputs.

    MabatchMabatch_as_completed
    —

    Run ainvoke in parallel on a list of inputs.

    MstreamMastreamMastream_log
    —

    Stream all output from a Runnable, as reported to the callback system.

    Mastream_events
    —

    Generate a stream of events.

    MtransformMatransformMwith_alisteners
    —

    Bind async lifecycle listeners to a Runnable.

    Mmap
    —

    Map a function to multiple iterables.

    Mwith_fallbacks
    —

    Add fallbacks to a Runnable, returning a new Runnable.

    Mas_tool
    —

    Create a BaseTool from a Runnable.

    Bind additional kwargs to a Runnable, returning a new Runnable.

    Bind lifecycle listeners to a Runnable, returning a new Runnable.

    The Run object contains information about the run, including its id, type, input, output, error, start_time, end_time, and any tags or metadata added to the run.