{"record":{"id":"d7b5a7e88fcbc399","repo":"run-llama/llama_index","slug":"chatstore-loading-requires-a-class-name","errorCode":null,"errorMessage":"ChatStore loading requires a class_name","messagePattern":"ChatStore loading requires a class_name","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/storage/chat_store/loading.py","lineNumber":13,"sourceCode":"from llama_index.core.storage.chat_store.base import BaseChatStore\nfrom llama_index.core.storage.chat_store.simple_chat_store import SimpleChatStore\n\nRECOGNIZED_CHAT_STORES = {\n    SimpleChatStore.class_name(): SimpleChatStore,\n}\n\n\ndef load_chat_store(data: dict) -> BaseChatStore:\n    \"\"\"Load a chat store from a dict.\"\"\"\n    chat_store_name = data.get(\"class_name\")\n    if chat_store_name is None:\n        raise ValueError(\"ChatStore loading requires a class_name\")\n\n    if chat_store_name not in RECOGNIZED_CHAT_STORES:\n        raise ValueError(f\"Invalid ChatStore name: {chat_store_name}\")\n\n    return RECOGNIZED_CHAT_STORES[chat_store_name].from_dict(data)\n","sourceCodeStart":1,"sourceCodeEnd":19,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/storage/chat_store/loading.py#L1-L19","documentation":"load_chat_store(data) reconstructs a chat store from a dict produced by its to_dict(). It requires a 'class_name' key to select the class; the dict is empty, missing the key, or malformed. Only classes registered in RECOGNIZED_CHAT_STORES (just SimpleChatStore) can be loaded.","triggerScenarios":"Calling load_chat_store({}) or load_chat_store({'messages': ...}) on a dict without 'class_name' -- e.g. hand-built config, a JSON file edited manually, or a payload from chat_store.to_dict() of an unregistered store type.","commonSituations":"Persisting chat history to JSON and reloading it; deserializing a payload written by a different chat store implementation (Redis/Postgres table export) or by a newer/older version whose dict schema differs.","solutions":["Ensure the dict came from SimpleChatStore.to_dict() and still contains its 'class_name' entry.","If loading arbitrary dicts, add the key explicitly: data['class_name'] = SimpleChatStore.class_name() before calling load_chat_store.","For other chat store types (RedisChatStore, DatabaseChatStore), instantiate them directly with their own connection args instead of load_chat_store.","Validate persisted payloads before reload (see validation below)."],"exampleFix":"# before\nstore = load_chat_store({'messages': saved})  # missing class_name\n\n# after\nfrom llama_index.core.storage.chat_store.simple_chat_store import SimpleChatStore\nstore = load_chat_store({'class_name': SimpleChatStore.class_name(), 'messages': saved})","handlingStrategy":"validation","validationCode":"from llama_index.core.storage.chat_store.loading import load_chat_store\n\ndef safe_load_chat_store(data: dict):\n    if not isinstance(data, dict) or 'class_name' not in data:\n        raise ValueError('Chat store payload must be a dict with a class_name key')\n    return load_chat_store(data)","typeGuard":"def is_loadable_chat_store_payload(data) -> bool:\n    return isinstance(data, dict) and isinstance(data.get('class_name'), str)","tryCatchPattern":"try:\n    store = load_chat_store(data)\nexcept ValueError as e:\n    if 'class_name' in str(e):\n        data = {**data, 'class_name': 'SimpleChatStore'}\n        store = load_chat_store(data)\n    else:\n        raise","preventionTips":["Only reload payloads produced by the same store's to_dict().","Schema-check persisted JSON (requires class_name) before calling load_chat_store.","Version your persisted chat-session files and validate on load."],"tags":["chat-store","serialization","persistence","validation","llama-index"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}