{"record":{"id":"23960e9027fb5ec4","repo":"keras-team/keras","slug":"argument-input-tensors-must-be-a-kerastensor-re","errorCode":null,"errorMessage":"Argument `input_tensors` must be a KerasTensor. Received invalid value: input_tensors={input_tensors}","messagePattern":"Argument `input_tensors` must be a KerasTensor\\. Received invalid value: input_tensors=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/models/cloning.py","lineNumber":313,"sourceCode":"        input_name = ref_input_layer.name\n        input_batch_shape = ref_input_layer.batch_shape\n        input_dtype = ref_input_layer._dtype\n        input_optional = ref_input_layer.optional\n    else:\n        input_name = None\n        input_dtype = None\n        input_batch_shape = None\n        input_optional = False\n\n    if input_tensors is not None:\n        if isinstance(input_tensors, (list, tuple)):\n            if len(input_tensors) != 1:\n                raise ValueError(\n                    \"Argument `input_tensors` must contain a single tensor.\"\n                )\n            input_tensors = input_tensors[0]\n        if not isinstance(input_tensors, backend.KerasTensor):\n            raise ValueError(\n                \"Argument `input_tensors` must be a KerasTensor. \"\n                f\"Received invalid value: input_tensors={input_tensors}\"\n            )\n        inputs = Input(\n            tensor=input_tensors,\n            name=input_name,\n            optional=input_optional,\n        )\n        new_layers = [inputs] + new_layers\n    else:\n        if input_batch_shape is not None:\n            inputs = Input(\n                batch_shape=input_batch_shape,\n                dtype=input_dtype,\n                name=input_name,\n                optional=input_optional,\n            )\n            new_layers = [inputs] + new_layers","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/models/cloning.py#L295-L331","documentation":"After cardinality is resolved, _clone_sequential_model validates that input_tensors is a backend KerasTensor - the clone is built by feeding it into keras.Input(tensor=...). Raw numpy arrays, tf.Tensors or torch tensors raise this ValueError.","triggerScenarios":"clone_model(seq_model, input_tensors=np.random.rand(4, 10)) or any framework-native tensor instead of a keras.KerasTensor.","commonSituations":"Passing real data batches instead of symbolic inputs; mixing framework-native tensors with Keras 3's symbolic KerasTensor.","solutions":["Create a symbolic input first: keras.Input(shape=..., dtype=...) and pass that instead.","If you only want a specific batch shape, pass input_batch_shape rather than real tensors."],"exampleFix":"# before\nclone = keras.models.clone_model(seq_model, input_tensors=np.zeros((4, 10)))\n\n# after\nnew_input = keras.Input(shape=(10,))\nclone = keras.models.clone_model(seq_model, input_tensors=new_input)","handlingStrategy":"type-guard","validationCode":"from keras.src import backend\nif not isinstance(input_tensors, backend.KerasTensor):\n    input_tensors = keras.Input(shape=tuple(input_tensors.shape[1:])) if hasattr(input_tensors, 'shape') else keras.Input(shape=(None,))","typeGuard":"from keras.src import backend\ndef is_keras_tensor(t) -> bool:\n    return isinstance(t, backend.KerasTensor)","tryCatchPattern":null,"preventionTips":["Pass symbolic keras.Input objects, never data batches or native tensors, to input_tensors."],"tags":["keras","models","clone-model","keras-tensor","type-check"],"backgroundTag":"wrong-argument-type","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}