{"record":{"id":"f4b718b40e03728a","repo":"keras-team/keras","slug":"only-instances-of-keras-layer-can-be-added-to-a","errorCode":null,"errorMessage":"Only instances of `keras.Layer` can be added to a Sequential model. Received: {layer} (of type {type(layer)})","messagePattern":"Only instances of `keras\\.Layer` can be added to a Sequential model\\. Received: (.+?) \\(of type (.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/models/sequential.py","lineNumber":97,"sourceCode":"        \"\"\"Adds a layer instance on top of the layer stack.\n\n        Args:\n            layer: layer instance.\n        \"\"\"\n        # Legacy case: if the first layer has an input_shape arg,\n        # use it to build an InputLayer.\n        if not self._layers:\n            if getattr(layer, \"_input_shape_arg\", None) is not None:\n                self.add(InputLayer(shape=layer._input_shape_arg))\n\n        # If we are passed a Keras tensor created by keras.Input(), we\n        # extract the input layer from its keras history and use that.\n        if hasattr(layer, \"_keras_history\"):\n            origin_layer = layer._keras_history[0]\n            if isinstance(origin_layer, InputLayer):\n                layer = origin_layer\n        if not isinstance(layer, Layer):\n            raise ValueError(\n                \"Only instances of `keras.Layer` can be \"\n                f\"added to a Sequential model. Received: {layer} \"\n                f\"(of type {type(layer)})\"\n            )\n        if not self._is_layer_name_unique(layer):\n            raise ValueError(\n                \"All layers added to a Sequential model \"\n                f\"should have unique names. Name '{layer.name}' is already \"\n                \"the name of a layer in this model. Update the `name` argument \"\n                \"to pass a unique name.\"\n            )\n        if (\n            isinstance(layer, InputLayer)\n            and self._layers\n            and isinstance(self._layers[0], InputLayer)\n        ):\n            raise ValueError(\n                f\"Sequential model '{self.name}' has already been configured \"","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/models/sequential.py#L79-L115","documentation":"Error \"Only instances of `keras.Layer` can be added to a Sequential model. Received: {layer} (of type {type(layer)})\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/models/sequential.py:97 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}