{"record":{"id":"db27d280042032d0","repo":"keras-team/keras","slug":"cannot-serialize-instance-because-it-doesn-t-imp","errorCode":null,"errorMessage":"Cannot serialize {instance} because it doesn't implement `get_config()`.","messagePattern":"Cannot serialize (.+?) because it doesn't implement `get_config\\(\\)`\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/legacy/saving/serialization.py","lineNumber":324,"sourceCode":"            # Any object of a different type needs to be converted to string or\n            # dict for serialization (e.g. custom functions, custom classes)\n            try:\n                serialized_item = serialize_keras_object(item)\n                if isinstance(serialized_item, dict) and not isinstance(\n                    item, dict\n                ):\n                    serialized_item[\"__passive_serialization__\"] = True\n                serialization_config[key] = serialized_item\n            except ValueError:\n                serialization_config[key] = item\n\n        name = object_registration.get_registered_name(instance.__class__)\n        return serialize_keras_class_and_config(\n            name, serialization_config, instance\n        )\n    if hasattr(instance, \"__name__\"):\n        return object_registration.get_registered_name(instance)\n    raise ValueError(\n        f\"Cannot serialize {instance} because it doesn't implement \"\n        \"`get_config()`.\"\n    )\n\n\ndef class_and_config_for_serialized_keras_object(\n    config,\n    module_objects=None,\n    custom_objects=None,\n    printable_module_name=\"object\",\n):\n    \"\"\"Returns the class name and config for a serialized keras object.\"\"\"\n\n    if (\n        not isinstance(config, dict)\n        or \"class_name\" not in config\n        or \"config\" not in config\n    ):","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/legacy/saving/serialization.py#L306-L342","documentation":"Raised by serialize_keras_object when the object being serialized does not implement get_config(). Keras serializes an object by calling its get_config() and wrapping the result with its class name; without that method there is no config to record, so serialization fails with this guard.","triggerScenarios":"Thrown at keras/src/legacy/saving/serialization.py:324 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Implement a get_config() method on your custom class returning a dict of constructor arguments, plus a from_config classmethod or __init__ accepting those arguments","Subclass keras.saving.SerializableObject or a Keras Layer/Loss/Metric base class which provides the protocol","Register a custom serializer via @keras.saving.register_keras_serializable on the class"],"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"}