{"record":{"id":"4bdd7e9219735af0","repo":"keras-team/keras","slug":"inputs-to-a-layer-should-be-tensors-got-x-of","errorCode":null,"errorMessage":"Inputs to a layer should be tensors. Got '{x}' (of type {type(x)}) as input for layer '{layer_name}'.","messagePattern":"Inputs to a layer should be tensors\\. Got '(.+?)' \\(of type (.+?)\\) as input for layer '(.+?)'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/input_spec.py","lineNumber":188,"sourceCode":"                + \"})`.\"\n            )\n        raise ValueError(\n            f'Layer \"{layer_name}\" expects {len(input_spec)} input(s),'\n            f\" but it received {len(inputs)} input tensors. \"\n            f\"Inputs received: {inputs}\"\n        )\n    for input_index, (x, spec) in enumerate(zip(inputs, input_spec)):\n        if spec is None:\n            continue\n        if x is None and spec.optional:\n            continue\n\n        # Having a shape/dtype is the only commonality of the various\n        # tensor-like objects that may be passed. The most common kind of\n        # invalid type we are guarding for is a Layer instance (Functional API),\n        # which does not have a `shape` attribute.\n        if not hasattr(x, \"shape\"):\n            raise ValueError(\n                f\"Inputs to a layer should be tensors. Got '{x}' \"\n                f\"(of type {type(x)}) as input for layer '{layer_name}'.\"\n            )\n\n        shape = backend.standardize_shape(x.shape)\n        ndim = len(shape)\n        # Check ndim.\n        if spec.ndim is not None and not spec.allow_last_axis_squeeze:\n            if ndim != spec.ndim:\n                raise ValueError(\n                    f\"Input {input_index} with name '{spec.name}' of layer \"\n                    f\"'{layer_name}' is incompatible with the layer: \"\n                    f\"expected ndim={spec.ndim}, found ndim={ndim}. \"\n                    f\"Full shape received: {shape}\"\n                )\n        if spec.max_ndim is not None:\n            if ndim is not None and ndim > spec.max_ndim:\n                raise ValueError(","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/input_spec.py#L170-L206","documentation":"Error \"Inputs to a layer should be tensors. Got '{x}' (of type {type(x)}) as input for layer '{layer_name}'.\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/layers/input_spec.py:188 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"}