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

    configurable_fields

    Configure particular Runnable fields at runtime.

    Copy
    configurable_fields(
      self,
      **kwargs: AnyConfigurableField = {}
    ) -> RunnableSerializable[Input, Output]
    from langchain_core.runnables import ConfigurableField
    from langchain_openai import ChatOpenAI
    
    model = ChatOpenAI(max_tokens=20).configurable_fields(
        max_tokens=ConfigurableField(
            id="output_token_number",
            name="Max tokens in the output",
            description="The maximum number of tokens in the output",
        )
    )
    
    # max_tokens = 20
    print(
        "max_tokens_20: ", model.invoke("tell me something about chess").content
    )
    
    # max_tokens = 200
    print(
        "max_tokens_200: ",
        model.with_config(configurable={"output_token_number": 200})
        .invoke("tell me something about chess")
        .content,
    )

    Parameters

    NameTypeDescription
    **kwargsAnyConfigurableField
    Default:{}

    A dictionary of ConfigurableField instances to configure.

    View source on GitHub