{"record":{"id":"80240e38c932772f","repo":"keras-team/keras","slug":"expected-all-elements-in-variables-to-be-tf-var","errorCode":null,"errorMessage":"Expected all elements in `variables` to be `tf.Variable` instances. Found instead the following types: {list(set(type(v) for v in variables))}","messagePattern":"Expected all elements in `variables` to be `tf\\.Variable` instances\\. Found instead the following types: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/export/saved_model_export_archive.py","lineNumber":234,"sourceCode":"        export_archive.write_out(\"path/to/location\")\n\n        # Reload the object\n        revived_object = tf.saved_model.load(\"path/to/location\")\n        # Retrieve the variables\n        optimizer_variables = revived_object.optimizer_variables\n        ```\n        \"\"\"\n        if not isinstance(variables, (list, tuple, set)):\n            raise ValueError(\n                \"Expected `variables` to be a list/tuple/set. \"\n                f\"Received instead object of type '{type(variables)}'.\"\n            )\n        # Ensure that all variables added are either tf.Variables\n        # or Variables created by Keras 3 with the TF or JAX backends.\n        if not all(\n            isinstance(v, (tf.Variable, backend.Variable)) for v in variables\n        ):\n            raise ValueError(\n                \"Expected all elements in `variables` to be \"\n                \"`tf.Variable` instances. Found instead the following types: \"\n                f\"{list(set(type(v) for v in variables))}\"\n            )\n        if backend.backend() == \"jax\":\n            variables = tree.flatten(\n                tree.map_structure(self._convert_to_tf_variable, variables)\n            )\n        setattr(self._tf_trackable, name, list(variables))\n\n    def write_out(self, filepath, options=None, verbose=True):\n        \"\"\"Write the corresponding SavedModel to disk.\n\n        Arguments:\n            filepath: `str` or `pathlib.Path` object.\n                Path where to save the artifact.\n            options: `tf.saved_model.SaveOptions` object that specifies\n                SavedModel saving options.","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/export/saved_model_export_archive.py#L216-L252","documentation":"Error \"Expected all elements in `variables` to be `tf.Variable` instances. Found instead the following types: {list(set(type(v) for v in variables))}\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/export/saved_model_export_archive.py:234 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"}