Mintplex-Labs/anything-llm · error · Error

Invalid chat type: ${chatType}

Error message

Invalid chat type: ${chatType}

What it means

Thrown by prepareChatsForExport() when chatType is neither 'workspace' nor 'embed'. The export pipeline queries two distinct tables (workspace_chats vs embed_chats) with different joins, so an unknown chat type has no data source. This guard runs after the format check and selects which model + query to use.

Source

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

  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}`);
  }

  if (format === "csv" || format === "json") {
    const preparedData = chats.map((chat) => {
      const responseJson = safeJsonParse(chat.response, {});
      const baseData = {
        id: chat.id,
        prompt: chat.prompt,
        response: responseJson.text,
        sent_at: chat.createdAt,
        // Only add attachments to the json format since we cannot arrange attachments in csv format
        ...(format === "json"
          ? {
              attachments:
                responseJson.attachments?.length > 0
                  ? responseJson.attachments.map((attachment) => ({
                      type: "image",
                      image: attachmentToDataUrl(attachment),

View on GitHub (pinned to 526360e320)

Solutions

  1. Pass exactly 'workspace' or 'embed' as chatType.
  2. Validate the value against a constant array at the controller and default to 'workspace' if absent.
  3. Return 400 with the list of allowed chat types when the value is invalid.
  4. Document the two supported chat types in your API client.

Example fix

// before
await prepareChatsForExport('csv', chatType); // chatType='api' -> throws

// after
const VALID = ['workspace','embed'];
const type = VALID.includes(chatType) ? chatType : 'workspace';
await prepareChatsForExport('csv', type);
Defensive patterns

Strategy: validation

Validate before calling

const VALID = ['workspace','embed'];
if (!VALID.includes(chatType))
  return res.status(400).json({ error: `chatType must be one of ${VALID.join(',')}` });

Type guard

type ChatType = 'workspace'|'embed';
function isChatType(v): v is ChatType { return v === 'workspace' || v === 'embed'; }

Try / catch

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

Prevention

When it happens

Trigger: Calling prepareChatsForExport(format, 'workspaces'), 'api', '', or any value other than the two supported ones. A client that sends chatType as a query string with a typo.

Common situations: An API consumer guessing the chatType enum; a frontend dropdown that previously offered a third, since-removed type; an integration hardcoded to an outdated value.

Related errors


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