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

    Chat LangChain

    What can I help with?

    Enter to sendยทShift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-corerunnablesbaseRunnablebind
    Methodโ—Since v1.8

    bind

    Copy
    bind(
        self,
        kwargs: Any = {},
    ) -> Runnable[Input, Output
    View source on GitHub
    ]

    Parameters

    NameTypeDescription
    **kwargsAny
    Default:{}

    Bind arguments to a Runnable, returning a new Runnable.

    Useful when a Runnable in a chain requires an argument that is not in the output of the previous Runnable or included in the user input.

    Example:

    from langchain_ollama import ChatOllama
    from langchain_core.output_parsers import StrOutputParser
    
    model = ChatOllama(model="llama3.1")
    
    # Without bind
    chain = model | StrOutputParser()
    
    chain.invoke("Repeat quoted words exactly: 'One two three four five.'")
    # Output is 'One two three four five.'
    
    # With bind
    chain = model.bind(stop=["three"]) | StrOutputParser()
    
    chain.invoke("Repeat quoted words exactly: 'One two three four five.'")
    # Output is 'One two'

    The arguments to bind to the Runnable.