Mintplex-Labs/anything-llm · error

${embed.chat_mode} is not a valid mode.

Error message

${embed.chat_mode} is not a valid mode.

What it means

Mode validation inside canRespond: embed.chat_mode (a persisted column on the embed config) must be one of VALID_CHAT_MODE — ['automatic','chat','query'] in server/utils/chats/stream.js. If the stored value is anything else, EVERY message to that embed returns 400 with '<mode> is not a valid mode.'. This is a data problem on the embed config row, not something the widget can influence per-request.

Source

Thrown at server/utils/middleware/embedMiddleware.js:112

      });
      return;
    }

    const { sessionId, message } = reqBody(request);
    if (typeof sessionId !== "string" || !validate(String(sessionId))) {
      response.status(404).json({
        id: uuidv4(),
        type: "abort",
        textResponse: null,
        sources: [],
        close: true,
        error: "Invalid session ID.",
      });
      return;
    }

    if (!message?.length || !VALID_CHAT_MODE.includes(embed.chat_mode)) {
      response.status(400).json({
        id: uuidv4(),
        type: "abort",
        textResponse: null,
        sources: [],
        close: true,
        error: !message?.length
          ? "Message is empty."
          : `${embed.chat_mode} is not a valid mode.`,
      });
      return;
    }

    if (
      !isNaN(embed.max_chats_per_day) &&
      Number(embed.max_chats_per_day) > 0
    ) {
      const dailyChatCount = await EmbedChats.count({
        embed_id: embed.id,

View on GitHub (pinned to 3aec848f28)

Solutions

  1. Re-save the embed in the admin UI with mode Chat or Query — this rewrites chat_mode with a valid value
  2. Or update the embeds table row directly: set chat_mode to 'chat' or 'query'
  3. If the row is beyond repair, recreate the embed and swap the embedId in your page snippet
  4. Verify with a single test message after the change — the check runs per request, so the fix takes effect immediately

Example fix

-- before: embed config row
UPDATE embed_configs SET chat_mode = 'Chat' ...;  -- capitalized -> every message 400

-- after
UPDATE embed_configs SET chat_mode = 'chat' WHERE uuid = '<embed-uuid>';
Defensive patterns

Strategy: validation

Validate before calling

const VALID = ['automatic', 'chat', 'query']; // server/utils/chats/stream.js
if (!VALID.includes(embed.chat_mode))
  throw new Error(`Embed ${embed.uuid} has invalid chat_mode '${embed.chat_mode}' — re-save it in admin`);

Type guard

const hasValidChatMode = (embed) =>
  ['automatic', 'chat', 'query'].includes(embed?.chat_mode);

Try / catch

if (res.status === 400) {
  const data = await res.json();
  if (/is not a valid mode/.test(data.error ?? ''))
    flagEmbedConfigForRepair(data.error); // fix the stored embed row, not the request
}

Prevention

When it happens

Trigger: An embed config row whose chat_mode was manually edited in the DB to an invalid value; rows migrated from an older version with a retired mode string; API-created embeds that bypassed creation-time validation.

Common situations: Direct SQL fixes to embed configs; importing embed rows between instances; typos like 'Chat' (case-sensitive) stored by a script.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/0c2dfa5fc7814614. Report an issue: GitHub.