Mintplex-Labs/anything-llm · warning

${resolvedMode} is not a valid mode.

Error message

${resolvedMode} is not a valid mode.

What it means

HTTP 400 from POST /api/v1/workspace/:slug/thread/:threadSlug/chat when the effective mode (request mode ?? workspace.chatMode) is outside VALID_CHAT_MODE = ['automatic','chat','query']. Because the fallback reads the workspace's stored chatMode, the request can be well-formed and still fail if the workspace row holds a stale value.

Source

Thrown at server/endpoints/api/workspaceThread/index.js:435

        });
        if (!thread) {
          response.status(404).json({
            id: uuidv4(),
            type: "abort",
            textResponse: null,
            sources: [],
            close: true,
            error: `Thread ${threadSlug} not found.`,
          });
          return;
        }

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

        const user = userId ? await User.get({ id: Number(userId) }) : null;
        const result = await ApiChatHandler.chatSync({
          workspace,
          message,
          mode: resolvedMode,
          user,

View on GitHub (pinned to 3aec848f28)

Solutions

  1. Send mode explicitly as 'automatic', 'chat', or 'query'
  2. If omitting mode, repair the workspace's chatMode via the workspace update endpoint
  3. Validate mode against the allowed list before sending
  4. After instance upgrades, run a quick chat against each workspace to smoke-test stored modes

Example fix

// before
body: JSON.stringify({ message, mode: 'agent' })
// after
const MODES = ['automatic', 'chat', 'query'];
body: JSON.stringify({ message, mode: MODES.includes(mode) ? mode : 'chat' })
Defensive patterns

Strategy: type-guard

Validate before calling

const VALID = ['automatic', 'chat', 'query'];
const body = { message, mode: VALID.includes(mode) ? mode : 'chat' };

Type guard

function isValidChatMode(m) { return ['automatic', 'chat', 'query'].includes(m); }

Prevention

When it happens

Trigger: mode:'agent' sent by legacy clients; mode omitted while the workspace's chatMode column contains an outdated/invalid value from an older AnythingLLM build; case or whitespace mismatches like 'Query'.

Common situations: Upgrading an instance with old workspaces; code samples predating the 'automatic' mode; hand-edited database rows.

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/a556da8cd01d8d6b. Report an issue: GitHub.