{"record":{"id":"16a65e13df6b9a21","repo":"keras-team/keras","slug":"layers-added-to-a-sequential-model-can-only-have-a","errorCode":null,"errorMessage":"Layers added to a Sequential model can only have a single required positional argument, the input tensor. Layer {layer.__class__.__name__} has multiple required positional arguments: {required_positional_args}","messagePattern":"Layers added to a Sequential model can only have a single required positional argument, the input tensor\\. Layer (.+?) has multiple required positional arguments: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/models/sequential.py","lineNumber":225,"sourceCode":"                        inspect.Parameter.POSITIONAL_ONLY,\n                        inspect.Parameter.POSITIONAL_OR_KEYWORD,\n                    )\n                ]\n                required_positional_args = [\n                    param\n                    for param in positional_args\n                    if param.default == inspect.Parameter.empty\n                ]\n                if not positional_args:\n                    raise ValueError(\n                        \"Layers added to a Sequential model should \"\n                        \"have a single positional argument, the \"\n                        \"input tensor. Layer \"\n                        f\"{layer.__class__.__name__} has no \"\n                        \"positional arguments.\"\n                    )\n                if len(required_positional_args) > 1:\n                    raise ValueError(\n                        \"Layers added to a Sequential model can \"\n                        \"only have a single required positional \"\n                        \"argument, the input tensor. Layer \"\n                        f\"{layer.__class__.__name__} has multiple \"\n                        \"required positional arguments: \"\n                        f\"{required_positional_args}\"\n                    )\n                raise e\n        outputs = x\n        self._functional = Functional(inputs=inputs, outputs=outputs)\n\n    def call(self, inputs, training=None, mask=None):\n        if self._functional:\n            return self._functional.call(inputs, training=training, mask=mask)\n\n        # Fallback: Just apply the layer sequence.\n        # This typically happens if `inputs` is a nested struct.\n        for layer in self.layers:","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/models/sequential.py#L207-L243","documentation":"Keras 3 Sequential inspects call() and requires exactly one required positional argument (the input tensor). A layer with multiple required positional arguments cannot be chained automatically, so build fails.","triggerScenarios":"class L(keras.layers.Layer): def call(self, inputs, bias): ... — then model.add(L()) and build","commonSituations":"Custom layers written with extra required hyperparameters in call(), or partial application of JAX/Flax style modules","solutions":["Move extra required arguments to __init__ or give them defaults in call()","Wrap the layer in a Lambda that closes over the extra values","Subclass Layer with call(self, inputs) only"],"exampleFix":"# before\nclass MyLayer(keras.layers.Layer):\n    def call(self, inputs, scale): ...\n\n# after\nclass MyLayer(keras.layers.Layer):\n    def __init__(self, scale):\n        super().__init__()\n        self.scale = scale\n    def call(self, inputs): ...","handlingStrategy":"validation","validationCode":"import inspect\nsig = inspect.signature(layer.call)\nreq = [n for n, p in sig.parameters.items()\n       if p.default is inspect.Parameter.empty\n       and p.kind in (p.POSITIONAL_ONLY, p.POSITIONAL_OR_KEYWORD)]\nassert len(req) <= 1, f'{layer.name} requires {req}'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give extra call arguments defaults in custom layers","Wrap multi-argument layers in a Lambda with closed-over constants"],"tags":["keras","sequential","layer","required-arguments"],"backgroundTag":"layer-signature-mismatch","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}