{"record":{"id":"e3d95cbadeb873ca","repo":"keras-team/keras","slug":"add-weight-takes-at-most-3-positional-arguments","errorCode":null,"errorMessage":"add_weight() takes at most 3 positional arguments but {len(args)} were given.","messagePattern":"add_weight\\(\\) takes at most 3 positional arguments but (.+?) were given\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/layer.py","lineNumber":579,"sourceCode":"                optimizer update, or string name of a built-in constraint.\n                Defaults to `None`.\n            aggregation: Optional string, one of `None`, `\"none\"`, `\"mean\"`,\n                `\"sum\"` or `\"only_first_replica\"`. Annotates the variable with\n                the type of multi-replica aggregation to be used for this\n                variable when writing custom data parallel training loops.\n                Defaults to `\"none\"`.\n            overwrite_with_gradient: Boolean, whether to overwrite the variable\n                with the computed gradient. This is useful for float8 training.\n                Defaults to `False`.\n            name: String name of the variable. Useful for debugging purposes.\n        \"\"\"\n        self._check_super_called()\n        if args:\n            # `args` is only kept to detect the legacy Keras 2 call style\n            # (`add_weight(shape, initializer, dtype, ...)`) and raise a clear\n            # error for positional `name`.\n            if len(args) > 3:\n                raise TypeError(\n                    \"add_weight() takes at most 3 positional arguments \"\n                    f\"but {len(args)} were given.\"\n                )\n            shape_arg = args[0]\n            if isinstance(shape_arg, str):\n                raise ValueError(\n                    \"`name` must be passed as a keyword argument. \"\n                    f\"Received: add_weight('{shape_arg}', ...). \"\n                    f\"Use: add_weight(shape=..., name='{shape_arg}').\"\n                )\n            if shape is not None:\n                raise ValueError(\n                    \"`shape` was passed both positionally and as \"\n                    \"a keyword argument.\"\n                )\n            shape = shape_arg\n            if len(args) > 1:\n                if initializer is not None:","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/layer.py#L561-L597","documentation":"Error \"add_weight() takes at most 3 positional arguments but {len(args)} were given.\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/layers/layer.py:579 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}