keras-team/keras · error · ValueError
Only instances of `keras.Layer` can be added to a Sequential
Error message
Only instances of `keras.Layer` can be added to a Sequential model. Received: {layer} (of type {type(layer)}) What it means
Error "Only instances of `keras.Layer` can be added to a Sequential model. Received: {layer} (of type {type(layer)})" thrown in keras-team/keras.
Source
Thrown at keras/src/models/sequential.py:97
"""Adds a layer instance on top of the layer stack.
Args:
layer: layer instance.
"""
# Legacy case: if the first layer has an input_shape arg,
# use it to build an InputLayer.
if not self._layers:
if getattr(layer, "_input_shape_arg", None) is not None:
self.add(InputLayer(shape=layer._input_shape_arg))
# If we are passed a Keras tensor created by keras.Input(), we
# extract the input layer from its keras history and use that.
if hasattr(layer, "_keras_history"):
origin_layer = layer._keras_history[0]
if isinstance(origin_layer, InputLayer):
layer = origin_layer
if not isinstance(layer, Layer):
raise ValueError(
"Only instances of `keras.Layer` can be "
f"added to a Sequential model. Received: {layer} "
f"(of type {type(layer)})"
)
if not self._is_layer_name_unique(layer):
raise ValueError(
"All layers added to a Sequential model "
f"should have unique names. Name '{layer.name}' is already "
"the name of a layer in this model. Update the `name` argument "
"to pass a unique name."
)
if (
isinstance(layer, InputLayer)
and self._layers
and isinstance(self._layers[0], InputLayer)
):
raise ValueError(
f"Sequential model '{self.name}' has already been configured "View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/models/sequential.py:97 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/f4b718b40e03728a.
Report an issue: GitHub.