{"record":{"id":"06409cf99d4a1216","repo":"langchain-ai/langchain","slug":"found-field-name-supplied-twice","errorCode":null,"errorMessage":"Found {field_name} supplied twice.","messagePattern":"Found (.+?) supplied twice\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/utils/utils.py","lineNumber":237,"sourceCode":") -> dict[str, Any]:\n    \"\"\"Build `model_kwargs` param from Pydantic constructor values.\n\n    Args:\n        values: All init args passed in by user.\n        all_required_field_names: All required field names for the pydantic class.\n\n    Returns:\n        Extra kwargs.\n\n    Raises:\n        ValueError: If a field is specified in both `values` and `extra_kwargs`.\n        ValueError: If a field is specified in `model_kwargs`.\n    \"\"\"\n    extra_kwargs = values.get(\"model_kwargs\", {})\n    for field_name in list(values):\n        if field_name in extra_kwargs:\n            msg = f\"Found {field_name} supplied twice.\"\n            raise ValueError(msg)\n        if field_name not in all_required_field_names:\n            warnings.warn(\n                f\"\"\"WARNING! {field_name} is not default parameter.\n                {field_name} was transferred to model_kwargs.\n                Please confirm that {field_name} is what you intended.\"\"\",\n                stacklevel=7,\n            )\n            extra_kwargs[field_name] = values.pop(field_name)\n\n    invalid_model_kwargs = all_required_field_names.intersection(extra_kwargs.keys())\n    if invalid_model_kwargs:\n        warnings.warn(\n            f\"Parameters {invalid_model_kwargs} should be specified explicitly. \"\n            f\"Instead they were passed in as part of `model_kwargs` parameter.\",\n            stacklevel=7,\n        )\n        for k in invalid_model_kwargs:\n            values[k] = extra_kwargs.pop(k)","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/utils/utils.py#L219-L255","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove the duplicated key from `model_kwargs` and pass it only as a top-level argument (or vice versa).","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}`.","After upgrading an integration, review its new explicit parameters and migrate them out of `model_kwargs`."],"exampleFix":"# before\nllm = ChatOpenAI(\n    model=\"gpt-4o\",\n    model_kwargs={\"model\": \"gpt-4o-mini\", \"temperature\": 0},\n)\n\n# after\nllm = ChatOpenAI(\n    model=\"gpt-4o\",\n    model_kwargs={\"temperature\": 0},\n)","handlingStrategy":"validation","validationCode":"def split_kwargs(llm_cls, explicit: dict, model_kwargs: dict) -> dict:\n    \"\"\"Drop model_kwargs entries that collide with explicit constructor args.\"\"\"\n    return {k: v for k, v in model_kwargs.items() if k not in explicit}","typeGuard":null,"tryCatchPattern":"try:\n    llm = ChatOpenAI(**cfg)\nexcept ValueError as e:\n    if \"supplied twice\" in str(e):\n        # de-duplicate and retry once\n        dup = next(k for k in cfg[\"model_kwargs\"] if k in cfg)\n        cfg[\"model_kwargs\"].pop(dup)\n        llm = ChatOpenAI(**cfg)\n    else:\n        raise","preventionTips":["Treat `model_kwargs` as provider-only extras; every named parameter of the class goes top-level.","When merging config layers, pop overlapping keys from `model_kwargs` before construction.","Add a unit test asserting your production config constructs without `ValueError`."],"tags":["configuration","pydantic","chat-model"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}