{"record":{"id":"87610939f19e7c45","repo":"keras-team/keras","slug":"input-tensors-must-have-the-same-structure-as-mo","errorCode":null,"errorMessage":"`input_tensors` must have the same structure as model.input\\nReference structure: {model.input}\\nReceived structure: {input_tensors}","messagePattern":"`input_tensors` must have the same structure as model\\.input\\\\nReference structure: (.+?)\\\\nReceived structure: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/models/cloning.py","lineNumber":392,"sourceCode":"    if not isinstance(model, Functional):\n        raise ValueError(\n            \"Expected `model` argument \"\n            f\"to be a Functional Model instance. Received: model={model}\"\n        )\n\n    if input_tensors is not None:\n        if not all(\n            isinstance(x, backend.KerasTensor)\n            for x in tree.flatten(input_tensors)\n        ):\n            raise ValueError(\n                \"All entries in `input_tensors` must be KerasTensors. \"\n                f\"Received invalid values: inputs_tensors={input_tensors}\"\n            )\n        try:\n            tree.assert_same_structure(input_tensors, model.input)\n        except ValueError as e:\n            raise ValueError(\n                \"`input_tensors` must have the same structure as model.input\"\n                f\"\\nReference structure: {model.input}\"\n                f\"\\nReceived structure: {input_tensors}\"\n            ) from e\n    else:\n        input_tensors = tree.map_structure(\n            lambda x: Input(batch_shape=x.shape, dtype=x.dtype, name=x.name),\n            model.input,\n        )\n\n    def operation_fn(layer):\n        new_layer = clone_function(layer)\n        return new_layer\n\n    output_tensors = model._run_through_graph(\n        input_tensors,\n        operation_fn=operation_fn,\n        call_fn=call_function,","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/models/cloning.py#L374-L410","documentation":"Structural guard in _clone_functional_model: the provided input_tensors must mirror the exact nesting structure of model.input (same dict keys / list / tuple shape). After flattening, layers are zipped positionally with the placeholders, so a mismatched structure (e.g. a flat list for a dict of inputs, or wrong nesting depth) would silently wire inputs to the wrong layers and is rejected instead.","triggerScenarios":"Thrown at keras/src/models/cloning.py:392 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Mirror model.input's structure exactly: pass a dict with the same keys if the model was built from dict inputs, or a list with the same length and nesting","Use tree.structure(model.input) as a reference, or omit input_tensors to let placeholders be generated automatically"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}