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-corerunnablesconfigurableRunnableConfigurableAlternatives
    Class●Since v0.1

    RunnableConfigurableAlternatives

    Copy
    RunnableConfigurableAlternatives(
      self,
      *
    args
    :
    Any
    =
    (
    )
    ,
    **
    kwargs
    :
    Any
    =
    {
    }
    )

    Bases

    DynamicRunnable[Input, Output]

    Attributes

    attribute
    which: ConfigurableField
    attribute
    alternatives: dict[str, Runnable[Input, Output] | Callable[[], Runnable[Input, Output]]]
    attribute
    default_key: str
    attribute
    prefix_keys: bool
    attribute
    config_specs: list[ConfigurableFieldSpec]

    Methods

    method
    configurable_fields

    Inherited fromDynamicRunnable

    Attributes

    Adefault: RunnableSerializable[Input, Output]
    —

    The default Runnable to use.

    Aconfig: RunnableConfig | None
    —

    The configuration to use.

    Amodel_configAInputType: type[Input]AOutputType: type[Output]

    Methods

    Mis_lc_serializable
    —

    Return True as this class is serializable.

    Mget_lc_namespace
    —

    Get the namespace of the LangChain object.

    Mget_input_schemaMget_output_schemaMget_graph

    Inherited fromRunnableSerializable

    Attributes

    Aname: str | None
    —

    The name of the Runnable.

    Amodel_config

    Methods

    Mto_json
    —

    Serialize the Runnable to JSON.

    M

    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 | None
    —

    The name of the Runnable. Used for debugging and tracing.

    AInputType: type[Input]
    —

    Input type.

    AOutputType: type[Output]
    —

    Output Type.

    A
    View source on GitHub

    Runnable that can be dynamically configured.

    A RunnableConfigurableAlternatives should be initiated using the configurable_alternatives method of a Runnable or can be initiated directly as well.

    Here is an example of using a RunnableConfigurableAlternatives that uses alternative prompts to illustrate its functionality:

    from langchain_core.runnables import ConfigurableField
    from langchain_openai import ChatOpenAI
    
    # This creates a RunnableConfigurableAlternatives for Prompt Runnable
    # with two alternatives.
    prompt = PromptTemplate.from_template(
        "Tell me a joke about {topic}"
    ).configurable_alternatives(
        ConfigurableField(id="prompt"),
        default_key="joke",
        poem=PromptTemplate.from_template("Write a short poem about {topic}"),
    )
    
    # When invoking the created RunnableSequence, you can pass in the
    # value for your ConfigurableField's id which in this case will either be
    # `joke` or `poem`.
    chain = prompt | ChatOpenAI(model="gpt-5.4-mini")
    
    # The `with_config` method brings in the desired Prompt Runnable in your
    # Runnable Sequence.
    chain.with_config(configurable={"prompt": "poem"}).invoke({"topic": "bears"})

    Equivalently, you can initialize RunnableConfigurableAlternatives directly and use in LCEL in the same way:

    from langchain_core.runnables import ConfigurableField
    from langchain_core.runnables.configurable import (
        RunnableConfigurableAlternatives,
    )
    from langchain_openai import ChatOpenAI
    
    prompt = RunnableConfigurableAlternatives(
        which=ConfigurableField(id="prompt"),
        default=PromptTemplate.from_template("Tell me a joke about {topic}"),
        default_key="joke",
        prefix_keys=False,
        alternatives={
            "poem": PromptTemplate.from_template("Write a short poem about {topic}")
        },
    )
    chain = prompt | ChatOpenAI(model="gpt-5.4-mini")
    chain.with_config(configurable={"prompt": "poem"}).invoke({"topic": "bears"})
    Mwith_config
    Mprepare
    —

    Prepare the Runnable for invocation.

    Minvoke
    Mainvoke
    Mbatch
    Mabatch
    Mstream
    Mastream
    Mtransform
    Matransform
    configurable_alternatives
    —

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

    M
    is_lc_serializable
    —

    Is this class 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
    —

    Serialize the object to JSON.

    Mto_json_not_implemented
    —

    Serialize a "not implemented" object.

    input_schema
    : type[BaseModel]
    —

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

    Aoutput_schema: type[BaseModel]
    —

    Output schema.

    Methods

    Mget_name
    —

    Get the name of the Runnable.

    Mget_input_schema
    —

    Get a Pydantic model that can be used to validate input to the Runnable.

    Mget_input_jsonschema
    —

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

    Mget_output_schema
    —

    Get a Pydantic model that can be used to validate output to the Runnable.

    Mget_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_graph
    —

    Return a graph representation of this Runnable.

    Mget_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
    —

    Assigns new fields to the dict output of this Runnable.

    Minvoke
    —

    Transform a single input into an output.

    Mainvoke
    —

    Transform a single input into an output.

    Mbatch
    —

    Default implementation runs invoke in parallel using a thread pool executor.

    Mbatch_as_completed
    —

    Run invoke in parallel on a list of inputs.

    Mabatch
    —

    Default implementation runs ainvoke in parallel using asyncio.gather.

    Mabatch_as_completed
    —

    Run ainvoke in parallel on a list of inputs.

    Mstream
    —

    Default implementation of stream, which calls invoke.

    Mastream
    —

    Default implementation of astream, which calls ainvoke.

    Mastream_log
    —

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

    Mastream_events
    —

    Generate a stream of events.

    Mstream_events
    —

    Generate a stream of events synchronously.

    Mtransform
    —

    Transform inputs to outputs.

    Matransform
    —

    Transform inputs to outputs.

    Mbind
    —

    Bind arguments to a Runnable, returning a new Runnable.

    Mwith_config
    —

    Bind config to a Runnable, returning a new Runnable.

    Mwith_listeners
    —

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

    Mwith_alisteners
    —

    Bind async lifecycle listeners to a Runnable.

    Mwith_types
    —

    Bind input and output types to a Runnable, returning a new Runnable.

    Mwith_retry
    —

    Create a new Runnable that retries the original Runnable on exceptions.

    Mmap
    —

    Return a new Runnable that maps a list of inputs to a list of outputs.

    Mwith_fallbacks
    —

    Add fallbacks to a Runnable, returning a new Runnable.

    Mas_tool
    —

    Create a BaseTool from a Runnable.

    The ConfigurableField to use to choose between alternatives.

    The alternatives to choose from.

    The enum value to use for the default option.

    Whether to prefix configurable fields of each alternative with a namespace of the form <which.id>==<alternative_key>, e.g. a key named "temperature" used by the alternative named "gpt3" becomes "model==gpt3/temperature".