langchain-ai/langchain · error · ValueError

Configuration key {key} not found in {self}: available keys

Error message

Configuration key {key} not found in {self}: available keys are {model_fields.keys()}

What it means

Raised by `Runnable.with_config`-style field configuration (the `configure`/`ConfigurableField` path at the end of `base.py`) when a keyword argument names a key that is not a field of the Runnable's pydantic model (`type(self).model_fields`). Runtime configurability can only override declared fields, so unknown keys raise `ValueError`, and the message lists the actually available field names for that instance.

Source

Thrown at libs/core/langchain_core/runnables/base.py:2897

                model.with_config(configurable={"output_token_number": 200})
                .invoke("tell me something about chess")
                .content,
            )
            ```
        """
        # Import locally to prevent circular import
        from langchain_core.runnables.configurable import (  # noqa: PLC0415
            RunnableConfigurableFields,
        )

        model_fields = type(self).model_fields
        for key in kwargs:
            if key not in model_fields:
                msg = (
                    f"Configuration key {key} not found in {self}: "
                    f"available keys are {model_fields.keys()}"
                )
                raise ValueError(msg)

        return RunnableConfigurableFields(default=self, fields=kwargs)

    def configurable_alternatives(
        self,
        which: ConfigurableField,
        *,
        default_key: str = "default",
        prefix_keys: bool = False,
        **kwargs: Runnable[Input, Output] | Callable[[], Runnable[Input, Output]],
    ) -> RunnableSerializable[Input, Output]:
        """Configure alternatives for `Runnable` objects that can be set at runtime.

        Args:
            which: The `ConfigurableField` instance that will be used to select the
                alternative.
            default_key: The default key to use if no alternative is selected.
            prefix_keys: Whether to prefix the keys with the `ConfigurableField` id.

View on GitHub (pinned to e32fa9a52e)

Solutions

  1. Read the error message — it prints `model_fields.keys()`, the exact set of configurable keys; use one of those names
  2. For renamed fields across versions, resolve the right name at runtime: `key = 'model' if 'model' in type(obj).model_fields else 'model_name'`
  3. Validate config keys against `type(runnable).model_fields` before applying them when the config comes from a file

Example fix

# before
chain.configure(model_name="gpt-4o-mini")  # ValueError: key not found

# after
fields = type(chain).model_fields
key = "model" if "model" in fields else "model_name"
chain.configure(**{key: "gpt-4o-mini"})
Defensive patterns

Strategy: validation

Validate before calling

from typing import Any
from langchain_core.runnables import Runnable

def filter_configurable(runnable: Runnable, config: dict[str, Any]) -> dict[str, Any]:
    fields = type(runnable).model_fields
    bad = set(config) - set(fields)
    if bad:
        msg = f"non-configurable keys {sorted(bad)}; available: {sorted(fields)}"
        raise ValueError(msg)
    return config

Type guard

def is_configurable_key(runnable: Runnable, key: str) -> bool:
    return key in type(runnable).model_fields

Try / catch

try:
    runnable.configure(**config)
except ValueError as e:
    if "not found in" in str(e):
        fields = type(runnable).model_fields
        usable = {k: v for k, v in config.items() if k in fields}
        runnable.configure(**usable)  # apply valid subset, log the rest
    else:
        raise

Prevention

When it happens

Trigger: `llm.with_config(tags=[...])` is fine, but the configurable-fields path `chain.configure(temperature=0.1)` on an object whose model has no `temperature` field (e.g. a prompt or a wrapper that stores settings under another name) raises. Also `.configure(model_name=...)` where the field is named `model`.

Common situations: Field-name drift between LangChain versions (e.g. `model_name` vs `model` on chat models); configuring through YAML/JSON run-config files where key names were hand-written; wrapping Runnables in custom classes and trying to configure inner attributes through the outer object.

Related errors


AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14). Data as JSON: /api/errors/be412a7b09059c8d. Report an issue: GitHub.