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

  1. Wrap the object in a custom Layer subclass whose call(self, inputs) takes the input tensor
  2. Wrap it in keras.layers.Lambda(lambda x: ...)
  3. 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

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


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/ec59e21f3060be96. Report an issue: GitHub.