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-corerunnablesbaseRunnablebind
    Method●Since v0.1

    bind

    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.

    Copy
    bind(
        self,
        **kwargs: Any = {},
    ) -> Runnable[Input, Output]

    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'

    Parameters

    NameTypeDescription
    **kwargsAny
    Default:{}

    The arguments to bind to the Runnable.

    View source on GitHub