langchain-ai/langchain · error · ValueError

Found {field_name} supplied twice.

Error message

Found {field_name} supplied twice.

What it means

Raised by the kwargs-filtering helper used in Pydantic validators of LangChain chat models (the `model_kwargs` merge logic in `langchain_core.utils.utils`). It fires when the same field name appears both as a top-level constructor argument (in `values`) and as a key inside the `model_kwargs` dict, because the resulting duplicate would be ambiguous when forwarded to the provider SDK.

Source

Thrown at libs/core/langchain_core/utils/utils.py:237

) -> dict[str, Any]:
    """Build `model_kwargs` param from Pydantic constructor values.

    Args:
        values: All init args passed in by user.
        all_required_field_names: All required field names for the pydantic class.

    Returns:
        Extra kwargs.

    Raises:
        ValueError: If a field is specified in both `values` and `extra_kwargs`.
        ValueError: If a field is specified in `model_kwargs`.
    """
    extra_kwargs = values.get("model_kwargs", {})
    for field_name in list(values):
        if field_name in extra_kwargs:
            msg = f"Found {field_name} supplied twice."
            raise ValueError(msg)
        if field_name not in all_required_field_names:
            warnings.warn(
                f"""WARNING! {field_name} is not default parameter.
                {field_name} was transferred to model_kwargs.
                Please confirm that {field_name} is what you intended.""",
                stacklevel=7,
            )
            extra_kwargs[field_name] = values.pop(field_name)

    invalid_model_kwargs = all_required_field_names.intersection(extra_kwargs.keys())
    if invalid_model_kwargs:
        warnings.warn(
            f"Parameters {invalid_model_kwargs} should be specified explicitly. "
            f"Instead they were passed in as part of `model_kwargs` parameter.",
            stacklevel=7,
        )
        for k in invalid_model_kwargs:
            values[k] = extra_kwargs.pop(k)

View on GitHub (pinned to e32fa9a52e)

Solutions

  1. Remove the duplicated key from `model_kwargs` and pass it only as a top-level argument (or vice versa).
  2. If merging config dicts programmatically, pop overlapping keys first: `model_kwargs = {k: v for k, v in model_kwargs.items() if k not in explicit_kwargs}`.
  3. After upgrading an integration, review its new explicit parameters and migrate them out of `model_kwargs`.

Example fix

# before
llm = ChatOpenAI(
    model="gpt-4o",
    model_kwargs={"model": "gpt-4o-mini", "temperature": 0},
)

# after
llm = ChatOpenAI(
    model="gpt-4o",
    model_kwargs={"temperature": 0},
)
Defensive patterns

Strategy: validation

Validate before calling

def split_kwargs(llm_cls, explicit: dict, model_kwargs: dict) -> dict:
    """Drop model_kwargs entries that collide with explicit constructor args."""
    return {k: v for k, v in model_kwargs.items() if k not in explicit}

Try / catch

try:
    llm = ChatOpenAI(**cfg)
except ValueError as e:
    if "supplied twice" in str(e):
        # de-duplicate and retry once
        dup = next(k for k in cfg["model_kwargs"] if k in cfg)
        cfg["model_kwargs"].pop(dup)
        llm = ChatOpenAI(**cfg)
    else:
        raise

Prevention

When it happens

Trigger: Constructing a chat model like `ChatOpenAI(model='gpt-4o', model_kwargs={'model': 'gpt-4o-mini'})`, or any integration whose validator routes unknown fields into `model_kwargs` when the same key was also passed explicitly. Any overlap between constructor kwargs and `model_kwargs` keys raises this.

Common situations: Copy-pasting configuration where `model` or `temperature` was moved to an explicit parameter but left in the `model_kwargs` dict; merging config dicts (base config + override) that both contain the same key; upgrading integrations that promoted a formerly-unknown kwarg to an explicit field, so it now collides with an existing `model_kwargs` entry.

Related errors


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