keras-team/keras · error · ValueError
Layers added to a Sequential model can only have a single re
Error message
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} What it means
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.
Source
Thrown at keras/src/models/sequential.py:225
inspect.Parameter.POSITIONAL_ONLY,
inspect.Parameter.POSITIONAL_OR_KEYWORD,
)
]
required_positional_args = [
param
for param in positional_args
if param.default == inspect.Parameter.empty
]
if not positional_args:
raise ValueError(
"Layers added to a Sequential model should "
"have a single positional argument, the "
"input tensor. Layer "
f"{layer.__class__.__name__} has no "
"positional arguments."
)
if len(required_positional_args) > 1:
raise ValueError(
"Layers added to a Sequential model can "
"only have a single required positional "
"argument, the input tensor. Layer "
f"{layer.__class__.__name__} has multiple "
"required positional arguments: "
f"{required_positional_args}"
)
raise e
outputs = x
self._functional = Functional(inputs=inputs, outputs=outputs)
def call(self, inputs, training=None, mask=None):
if self._functional:
return self._functional.call(inputs, training=training, mask=mask)
# Fallback: Just apply the layer sequence.
# This typically happens if `inputs` is a nested struct.
for layer in self.layers:View on GitHub (pinned to 7a34a03db6)
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
Example fix
# before
class MyLayer(keras.layers.Layer):
def call(self, inputs, scale): ...
# after
class MyLayer(keras.layers.Layer):
def __init__(self, scale):
super().__init__()
self.scale = scale
def call(self, inputs): ... Defensive patterns
Strategy: validation
Validate before calling
import inspect
sig = inspect.signature(layer.call)
req = [n for n, p in sig.parameters.items()
if p.default is inspect.Parameter.empty
and p.kind in (p.POSITIONAL_ONLY, p.POSITIONAL_OR_KEYWORD)]
assert len(req) <= 1, f'{layer.name} requires {req}' Prevention
- Give extra call arguments defaults in custom layers
- Wrap multi-argument layers in a Lambda with closed-over constants
When it happens
Trigger: class L(keras.layers.Layer): def call(self, inputs, bias): ... — then model.add(L()) and build
Common situations: Custom layers written with extra required hyperparameters in call(), or partial application of JAX/Flax style modules
Related errors
- Layers added to a Sequential model should have a single posi
- Cannot add call-context args after the layer has been called
- `call_function` argument is not supported with Sequential mo
- Expected `model` argument to be a `Sequential` model instanc
- Argument `input_tensors` must contain a single tensor.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/16a65e13df6b9a21.
Report an issue: GitHub.