{"record":{"id":"0c2dfa5fc7814614","repo":"Mintplex-Labs/anything-llm","slug":"embed-chat-mode-is-not-a-valid-mode","errorCode":null,"errorMessage":"${embed.chat_mode} is not a valid mode.","messagePattern":"(.+?) is not a valid mode\\.","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"server/utils/middleware/embedMiddleware.js","lineNumber":112,"sourceCode":"      });\n      return;\n    }\n\n    const { sessionId, message } = reqBody(request);\n    if (typeof sessionId !== \"string\" || !validate(String(sessionId))) {\n      response.status(404).json({\n        id: uuidv4(),\n        type: \"abort\",\n        textResponse: null,\n        sources: [],\n        close: true,\n        error: \"Invalid session ID.\",\n      });\n      return;\n    }\n\n    if (!message?.length || !VALID_CHAT_MODE.includes(embed.chat_mode)) {\n      response.status(400).json({\n        id: uuidv4(),\n        type: \"abort\",\n        textResponse: null,\n        sources: [],\n        close: true,\n        error: !message?.length\n          ? \"Message is empty.\"\n          : `${embed.chat_mode} is not a valid mode.`,\n      });\n      return;\n    }\n\n    if (\n      !isNaN(embed.max_chats_per_day) &&\n      Number(embed.max_chats_per_day) > 0\n    ) {\n      const dailyChatCount = await EmbedChats.count({\n        embed_id: embed.id,","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/middleware/embedMiddleware.js#L94-L130","documentation":"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.","triggerScenarios":"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.","commonSituations":"Direct SQL fixes to embed configs; importing embed rows between instances; typos like 'Chat' (case-sensitive) stored by a script.","solutions":["Re-save the embed in the admin UI with mode Chat or Query — this rewrites chat_mode with a valid value","Or update the embeds table row directly: set chat_mode to 'chat' or 'query'","If the row is beyond repair, recreate the embed and swap the embedId in your page snippet","Verify with a single test message after the change — the check runs per request, so the fix takes effect immediately"],"exampleFix":"-- before: embed config row\nUPDATE embed_configs SET chat_mode = 'Chat' ...;  -- capitalized -> every message 400\n\n-- after\nUPDATE embed_configs SET chat_mode = 'chat' WHERE uuid = '<embed-uuid>';","handlingStrategy":"validation","validationCode":"const VALID = ['automatic', 'chat', 'query']; // server/utils/chats/stream.js\nif (!VALID.includes(embed.chat_mode))\n  throw new Error(`Embed ${embed.uuid} has invalid chat_mode '${embed.chat_mode}' — re-save it in admin`);","typeGuard":"const hasValidChatMode = (embed) =>\n  ['automatic', 'chat', 'query'].includes(embed?.chat_mode);","tryCatchPattern":"if (res.status === 400) {\n  const data = await res.json();\n  if (/is not a valid mode/.test(data.error ?? ''))\n    flagEmbedConfigForRepair(data.error); // fix the stored embed row, not the request\n}","preventionTips":["Only set chat_mode via the admin UI or validated API paths","After manual DB edits or migrations, lint embed rows against the VALID_CHAT_MODE list","Add a startup check that queries for embeds with unknown chat_mode values"],"tags":["embed","enum","chat-mode","data-corruption","http-400"],"backgroundTag":"invalid-enum-value","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}