{"record":{"id":"fd003b6d9c623f65","repo":"keras-team/keras","slug":"backward-layer-need-to-be-a-keras-layers-layer","errorCode":null,"errorMessage":"`backward_layer` need to be a `keras.layers.Layer` instance. Received: {backward_layer}","messagePattern":"`backward_layer` need to be a `keras\\.layers\\.Layer` instance\\. Received: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/rnn/bidirectional.py","lineNumber":100,"sourceCode":"    model.compile(loss='categorical_crossentropy', optimizer='rmsprop')\n    ```\n    \"\"\"\n\n    def __init__(\n        self,\n        layer,\n        merge_mode=\"concat\",\n        weights=None,\n        backward_layer=None,\n        **kwargs,\n    ):\n        if not isinstance(layer, Layer):\n            raise ValueError(\n                \"Please initialize `Bidirectional` layer with a \"\n                f\"`keras.layers.Layer` instance. Received: {layer}\"\n            )\n        if backward_layer is not None and not isinstance(backward_layer, Layer):\n            raise ValueError(\n                \"`backward_layer` need to be a `keras.layers.Layer` \"\n                f\"instance. Received: {backward_layer}\"\n            )\n        if merge_mode not in [\"sum\", \"mul\", \"ave\", \"concat\", None]:\n            raise ValueError(\n                f\"Invalid merge mode. Received: {merge_mode}. \"\n                \"Merge mode should be one of \"\n                '{\"sum\", \"mul\", \"ave\", \"concat\", None}'\n            )\n        super().__init__(**kwargs)\n\n        # Recreate the forward layer from the original layer config, so that it\n        # will not carry over any state from the layer.\n        config = serialization_lib.serialize_keras_object(layer)\n        config[\"config\"][\"name\"] = (\n            f\"forward_{utils.removeprefix(layer.name, 'forward_')}\"\n        )\n        self.forward_layer = serialization_lib.deserialize_keras_object(config)","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/rnn/bidirectional.py#L82-L118","documentation":"Error \"`backward_layer` need to be a `keras.layers.Layer` instance. Received: {backward_layer}\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/layers/rnn/bidirectional.py:100 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"}