Mintplex-Labs/anything-llm · error · Error

Invalid export type: ${format}

Error message

Invalid export type: ${format}

What it means

Thrown by prepareChatsForExport() when the requested format is not a key in exportMap. The map supports exactly four formats: json, csv, jsonl, jsonAlpaca. Any other format string (including typos or the chat-history-file types like 'pdf') is rejected here because there is no converter function for it. This is the format-validation gate before any DB query runs.

Source

Thrown at server/utils/helpers/chat/convertTo.js:47

async function convertToJSON(preparedData) {
  return JSON.stringify(preparedData, null, 4);
}

// ref: https://raw.githubusercontent.com/gururise/AlpacaDataCleaned/main/alpaca_data.json
async function convertToJSONAlpaca(preparedData) {
  return JSON.stringify(preparedData, null, 4);
}

// You can validate JSONL outputs on https://jsonlines.org/validator/
async function convertToJSONL(workspaceChatsMap) {
  return Object.values(workspaceChatsMap)
    .map((workspaceChats) => JSON.stringify(workspaceChats))
    .join("\n");
}

async function prepareChatsForExport(format = "jsonl", chatType = "workspace") {
  if (!exportMap.hasOwnProperty(format))
    throw new Error(`Invalid export type: ${format}`);

  let chats;
  if (chatType === "workspace") {
    chats = await WorkspaceChats.whereWithData({}, null, null, {
      id: "asc",
    });
  } else if (chatType === "embed") {
    chats = await EmbedChats.whereWithEmbedAndWorkspace(
      {},
      null,
      {
        id: "asc",
      },
      null
    );
  } else {
    throw new Error(`Invalid chat type: ${chatType}`);
  }

View on GitHub (pinned to 526360e320)

Solutions

  1. Use one of the supported formats: 'json', 'csv', 'jsonl', 'jsonAlpaca'.
  2. At the call site, validate against exportMap keys or the exported validExportTypes array before invoking.
  3. For document-style exports (pdf/markdown/html), use sendChatHistoryFile, not prepareChatsForExport.
  4. Lowercase and trim the format input, then re-check, to absorb minor client variation.

Example fix

// before
const out = await prepareChatsForExport(format); // format='PDF' -> throws

// after
const validExportTypes = ['json','csv','jsonl','jsonAlpaca'];
const fmt = validExportTypes.includes(format) ? format : 'jsonl';
const out = await prepareChatsForExport(fmt);
Defensive patterns

Strategy: validation

Validate before calling

const validExportTypes = ['json','csv','jsonl','jsonAlpaca'];
if (!validExportTypes.includes(format))
  return res.status(400).json({ error: `format must be one of ${validExportTypes.join(',')}` });

Type guard

type ExportFormat = 'json'|'csv'|'jsonl'|'jsonAlpaca';
function isExportFormat(v): v is ExportFormat {
  return ['json','csv','jsonl','jsonAlpaca'].includes(v);
}

Try / catch

try {
  await prepareChatsForExport(format, chatType);
} catch (e) {
  if (e.message.startsWith('Invalid export type:')) return res.status(400).json({ error: e.message });
  throw e;
}

Prevention

When it happens

Trigger: Calling prepareChatsForExport('pdf'), 'xlsx', 'JSON' (case matters), '' or undefined-format exports. A frontend export button passing a format the data layer does not recognize.

Common situations: Confusing the data-export formats (convertTo.js: json/csv/jsonl/jsonAlpaca) with the chat-history-file formats (exportChatToFile.js: pdf/markdown/plaintext/json/html); a typo in a config; an older client after formats were renamed.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/a578f4d7cf4c4b19. Report an issue: GitHub.