keras-team/keras · error · ValueError
Layers added to a Sequential model should have a single posi
Error message
Layers added to a Sequential model should have a single positional argument, the input tensor. Layer {layer.__class__.__name__} has no positional arguments. What it means
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.
Source
Thrown at keras/src/models/sequential.py:217
return
except TypeError as e:
signature = inspect.signature(layer.call)
positional_args = [
param
for param in signature.parameters.values()
if param.kind
in (
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)View on GitHub (pinned to 7a34a03db6)
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
Example fix
# before model.add(NoArgLayer()) # after model.add(keras.layers.Lambda(lambda x: my_fn(x)))
Defensive patterns
Strategy: validation
Validate before calling
import inspect
sig = inspect.signature(layer.call)
pos = [p for p in sig.parameters.values()
if p.kind in (p.POSITIONAL_ONLY, p.POSITIONAL_OR_KEYWORD)]
assert len(pos) >= 1, f'{layer.__class__.__name__} has no positional args' Prevention
- Only add standard keras Layer subclasses to Sequential
- Wrap custom multi-argument callables in a keras.layers.Lambda or a custom Layer
When it happens
Trigger: Adding a custom object whose call(self) has no positional parameters to a Sequential, then calling build() or model(x)
Common situations: Wrapping functional-style helpers (numpy/scipy ops) or nn.Module-style code as Sequential layers
Related errors
- Layers added to a Sequential model can only have a single re
- 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/ec59e21f3060be96.
Report an issue: GitHub.