{"record":{"id":"bcacac5a594f1023","repo":"langchain-ai/langchain","slug":"f-name-got-multiple-values-for-argument-n","errorCode":null,"errorMessage":"{f.__name__}() got multiple values for argument {new!r}","messagePattern":"(.+?)\\(\\) got multiple values for argument (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/_api/deprecation.py","lineNumber":623,"sourceCode":"        old: The old parameter name.\n        new: The new parameter name.\n\n    Returns:\n        A decorator indicating that a parameter was renamed.\n\n    Example:\n        ```python\n        @_api.rename_parameter(\"3.1\", \"bad_name\", \"good_name\")\n        def func(good_name): ...\n        ```\n    \"\"\"\n\n    def decorator(f: Callable[_P, _R]) -> Callable[_P, _R]:\n        @functools.wraps(f)\n        def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _R:\n            if new in kwargs and old in kwargs:\n                msg = f\"{f.__name__}() got multiple values for argument {new!r}\"\n                raise TypeError(msg)\n            if old in kwargs:\n                warn_deprecated(\n                    since,\n                    removal=removal,\n                    message=f\"The parameter `{old}` of `{f.__name__}` was \"\n                    f\"deprecated in {since} and will be removed \"\n                    f\"in {removal} Use `{new}` instead.\",\n                )\n                kwargs[new] = kwargs.pop(old)\n            return f(*args, **kwargs)\n\n        return wrapper\n\n    return decorator\n","sourceCodeStart":605,"sourceCodeEnd":638,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/_api/deprecation.py#L605-L638","documentation":"Raised by the `rename_parameter(\"since\", \"old\", \"new\")` decorator's wrapper when the caller passes BOTH the old and the new parameter name as keyword arguments in one call. The wrapper cannot map both onto a single parameter, so instead of silently dropping one it raises TypeError, mirroring Python's own 'got multiple values' semantics.","triggerScenarios":"Given `@rename_parameter(\"3.1\", \"bad_name\", \"good_name\")` on `def func(good_name)`, calling `func(bad_name=1, good_name=2)` raises `TypeError: func() got multiple values for argument 'good_name'`. Only triggers via keywords; a single old-named keyword is still accepted (with a deprecation warning) and rewritten to the new name.","commonSituations":"Call sites mid-migration where one caller updated code to the new name while another layer (a wrapper, config-to-kwargs bridge, or merged dict) still injects the old name. Common in orchestration code that builds kwargs from multiple sources, e.g. `{**user_kwargs, **defaults}` where defaults still use the deprecated name.","solutions":["Delete the old-named key at the source: update the wrapper/defaults dict that still passes `bad_name` so only `good_name` reaches the call.","If kwargs are merged dynamically, pop the deprecated alias before calling: `merged.pop('bad_name', None)` once you've confirmed `good_name` is present (or keep only whichever key is set).","Enable `-W error::DeprecationWarning` in tests so the remaining old-name call sites surface before they collide with new-name callers."],"exampleFix":"# before\nfunc(bad_name=1, good_name=2)  # TypeError\n\n# after\nfunc(good_name=2)","handlingStrategy":"validation","validationCode":"def strip_renamed_kwargs(\n    kwargs: dict[str, object], old: str, new: str\n) -> dict[str, object]:\n    \"\"\"Keep at most one of old/new; prefer new when both are present by policy.\"\"\"\n    kwargs = dict(kwargs)\n    if new in kwargs:\n        kwargs.pop(old, None)  # or raise, if old must be authoritative\n    elif old in kwargs:\n        kwargs[new] = kwargs.pop(old)\n    return kwargs","typeGuard":null,"tryCatchPattern":"try:\n    func(good_name=1)\nexcept TypeError as e:\n    if 'multiple values' in str(e):\n        # resolve the duplicate kwarg source, then retry with a single name\n        ...\n    raise","preventionTips":["Never merge two kwarg dicts where one may hold the old name and the other the new; normalize to the new name at the boundary.","Run tests with -W error::DeprecationWarning so old-name call sites fail loudly before they collide with new-name callers.","Grep for the old parameter name during migrations and delete call sites instead of relying on the compat shim."],"tags":["deprecation","kwargs","api-migration"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}