{"record":{"id":"757a5c16dd32c7ab","repo":"keras-team/keras","slug":"all-cells-must-have-a-call-method-received-cell","errorCode":null,"errorMessage":"All cells must have a `call` method. Received cell without a `call` method: {cell}","messagePattern":"All cells must have a `call` method\\. Received cell without a `call` method: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/rnn/stacked_rnn_cells.py","lineNumber":38,"sourceCode":"    batch_size = 3\n    sentence_length = 5\n    num_features = 2\n    new_shape = (batch_size, sentence_length, num_features)\n    x = np.reshape(np.arange(30), new_shape)\n\n    rnn_cells = [keras.layers.LSTMCell(128) for _ in range(2)]\n    stacked_lstm = keras.layers.StackedRNNCells(rnn_cells)\n    lstm_layer = keras.layers.RNN(stacked_lstm)\n\n    result = lstm_layer(x)\n    ```\n    \"\"\"\n\n    def __init__(self, cells, **kwargs):\n        super().__init__(**kwargs)\n        for cell in cells:\n            if \"call\" not in dir(cell):\n                raise ValueError(\n                    \"All cells must have a `call` method. \"\n                    f\"Received cell without a `call` method: {cell}\"\n                )\n            if \"state_size\" not in dir(cell):\n                raise ValueError(\n                    \"All cells must have a `state_size` attribute. \"\n                    f\"Received cell without a `state_size`: {cell}\"\n                )\n        self.cells = cells\n\n    @property\n    def state_size(self):\n        return [c.state_size for c in self.cells]\n\n    @property\n    def output_size(self):\n        if getattr(self.cells[-1], \"output_size\", None) is not None:\n            return self.cells[-1].output_size","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/rnn/stacked_rnn_cells.py#L20-L56","documentation":"StackedRNNCells wraps a list of RNN cell objects (e.g. SimpleRNNCell instances) that an RNN layer steps through. Each cell must be a duck-typed RNN cell exposing both a `call` method and a `state_size` attribute; `__init__` checks every element with `dir(cell)` and rejects any object missing `call`. This fails at construction, before any computation.","triggerScenarios":"Passing plain objects, dicts, Keras Layer instances that are not cells, or class objects (instead of instantiated cell objects) to keras.layers.StackedRNNCells(cells=[...]). E.g. cells=[SimpleRNNCell] (class, not instance) or cells=[{'units': 8}].","commonSituations":"Migrating tf.keras code where cell lists were built differently; forgetting parentheses when instantiating cells; passing a Layer subclass that lacks the RNN cell interface; wrapping non-cell custom layers in a stacked RNN.","solutions":["Pass instantiated cell objects: StackedRNNCells(cells=[SimpleRNNCell(8), GRUCell(8)])","For custom cells, implement both call(self, inputs, states) returning (output, new_states) and a state_size attribute","Do not pass Layers or dicts; convert them to proper Keras cells first"],"exampleFix":"# before\ncells = keras.layers.StackedRNNCells([keras.layers.SimpleRNNCell, keras.layers.GRUCell])\n\n# after\ncells = keras.layers.StackedRNNCells([keras.layers.SimpleRNNCell(8), keras.layers.GRUCell(8)])","handlingStrategy":"type-guard","validationCode":"assert all(hasattr(c, 'call') and hasattr(c, 'state_size') for c in cells), 'all entries must be RNN cells'\nstacked = keras.layers.StackedRNNCells(cells=cells)","typeGuard":"def is_rnn_cell(obj) -> bool:\n    return hasattr(obj, 'call') and hasattr(obj, 'state_size')","tryCatchPattern":null,"preventionTips":["Always pass instantiated cell objects, never classes or dicts","Keep custom cells aligned with the Keras cell contract: call(inputs, states) returning (output, new_states) plus state_size"],"tags":["keras","rnn","stacked-cells","duck-typing"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}