{"record":{"id":"f21045cd51ccc0a1","repo":"danny-avila/LibreChat","slug":"invalid-librechat-file-format","errorCode":null,"errorMessage":"Invalid LibreChat file format","messagePattern":"Invalid LibreChat file format","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"api/server/utils/import/importers.js","lineNumber":296,"sourceCode":"\n          if (message.children && message.children.length > 0) {\n            flattenMessages(message.children, message.messageId, flatMessages);\n          }\n        }\n        return flatMessages;\n      };\n\n      const flatMessages = flattenMessages(messagesToImport);\n      cloneMessagesWithTimestamps(flatMessages, importBatchBuilder);\n    } else if (messagesToImport) {\n      cloneMessagesWithTimestamps(messagesToImport, importBatchBuilder);\n      for (const message of messagesToImport) {\n        if (!firstMessageDate && message.createdAt) {\n          firstMessageDate = new Date(message.createdAt);\n        }\n      }\n    } else {\n      throw new Error('Invalid LibreChat file format');\n    }\n\n    if (firstMessageDate === 'Invalid Date') {\n      firstMessageDate = null;\n    }\n\n    importBatchBuilder.finishConversation(\n      jsonData.title,\n      firstMessageDate ?? new Date(),\n      options,\n      defaultModel,\n    );\n    await importBatchBuilder.saveBatch();\n    logger.debug(`user: ${requestUserId} | Conversation \"${jsonData.title}\" imported`);\n  } catch (error) {\n    logger.error(`user: ${requestUserId} | Error creating conversation from LibreChat file`, error);\n    throw error;\n  }","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/server/utils/import/importers.js#L278-L314","documentation":"Thrown by importLibreChatConvo (utils/import/importers.js) when, after the conversationId check passed, none of the message-source branches apply — jsonData.recursive is false and messagesToImport is falsy. The file looked like a LibreChat export (it had conversationId) but its messages/messagesTree resolved to an empty or undefined payload, so there is nothing to clone.","triggerScenarios":"A LibreChat export where messagesTree and messages are both empty arrays or undefined; messagesTree present but every node filtered out (no text/content); an export truncated so the messages section is missing.","commonSituations":"Exporting an empty conversation; hand-editing the export and dropping the messages array; schema drift between export and import versions of LibreChat.","solutions":["Open the file and confirm jsonData.messages (or jsonData.messagesTree) is a non-empty array of message objects with text or content.","Re-export the conversation ensuring it contains at least one message.","If the export legitimately has zero messages, skip the import rather than submitting the file."],"exampleFix":"// before: file has conversationId but empty messages\n// after: ensure messages payload is populated\nif (!jsonData.messages?.length && !jsonData.messagesTree?.length) {\n  throw new Error('Nothing to import: export contains no messages');\n}","handlingStrategy":"validation","validationCode":"const messagesToImport = jsonData.messagesTree || jsonData.messages;\nif (!messagesToImport || (Array.isArray(messagesToImport) && messagesToImport.length === 0)) {\n  throw new Error('Invalid LibreChat file format');\n}","typeGuard":"const hasImportableMessages = (j) => {\n  const m = j?.messagesTree ?? j?.messages;\n  return Array.isArray(m) && m.length > 0;\n};","tryCatchPattern":"try {\n  await importer(jsonData, requestUserId, builderFactory, userRole);\n} catch (err) {\n  if (err.message === 'Invalid LibreChat file format') {\n    return res.status(400).json({ message: 'Export contains no importable messages.' });\n  }\n  throw err;\n}","preventionTips":["Ensure LibreChat exports include a non-empty messages or messagesTree array.","Reject empty exports before submission.","Keep export/import schemas aligned across versions."],"tags":["import","validation","librechat","format-detection"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}