{"record":{"id":"ec59e21f3060be96","repo":"keras-team/keras","slug":"layers-added-to-a-sequential-model-should-have-a-s","errorCode":null,"errorMessage":"Layers added to a Sequential model should have a single positional argument, the input tensor. Layer {layer.__class__.__name__} has no positional arguments.","messagePattern":"Layers added to a Sequential model should have a single positional argument, the input tensor\\. Layer (.+?) has no positional arguments\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/models/sequential.py","lineNumber":217,"sourceCode":"                return\n            except TypeError as e:\n                signature = inspect.signature(layer.call)\n                positional_args = [\n                    param\n                    for param in signature.parameters.values()\n                    if param.kind\n                    in (\n                        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)","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/models/sequential.py#L199-L235","documentation":"When building a Sequential, Keras inspects each layer's call() signature to drive functional graph construction. A layer whose call() takes no positional arguments cannot accept the input tensor, so Keras raises this error during build.","triggerScenarios":"Adding a custom object whose call(self) has no positional parameters to a Sequential, then calling build() or model(x)","commonSituations":"Wrapping functional-style helpers (numpy/scipy ops) or nn.Module-style code as Sequential layers","solutions":["Wrap the object in a custom Layer subclass whose call(self, inputs) takes the input tensor","Wrap it in keras.layers.Lambda(lambda x: ...)","Give call() a positional inputs parameter"],"exampleFix":"# before\nmodel.add(NoArgLayer())\n\n# after\nmodel.add(keras.layers.Lambda(lambda x: my_fn(x)))","handlingStrategy":"validation","validationCode":"import inspect\nsig = inspect.signature(layer.call)\npos = [p for p in sig.parameters.values()\n       if p.kind in (p.POSITIONAL_ONLY, p.POSITIONAL_OR_KEYWORD)]\nassert len(pos) >= 1, f'{layer.__class__.__name__} has no positional args'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only add standard keras Layer subclasses to Sequential","Wrap custom multi-argument callables in a keras.layers.Lambda or a custom Layer"],"tags":["keras","sequential","layer","introspection"],"backgroundTag":"layer-signature-mismatch","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}