Mintplex-Labs/anything-llm · error · Error

Privatemode chat: ${this.model} is not valid or defined mode

Error message

Privatemode chat: ${this.model} is not valid or defined model for chat completion!

What it means

Thrown by PrivatemodeLLM.getChatCompletion when `!this.model` is true. Privatemode has NO default model — this.model is `modelPreference || process.env.PRIVATEMODE_LLM_MODEL_PREF`, so if neither was supplied it stays undefined and the guard rejects the request before contacting the server.

Source

Thrown at server/utils/AiProviders/privatemode/index.js:145

    attachments = [],
  }) {
    const prompt = {
      role: "system",
      content: `${systemPrompt}${this.#appendContext(contextTexts)}`,
    };
    return [
      prompt,
      ...formatChatHistory(chatHistory, this.#generateContent),
      {
        role: "user",
        content: this.#generateContent({ userPrompt, attachments }),
      },
    ];
  }

  async getChatCompletion(messages = null, { temperature = 0.7 }) {
    if (!this.model)
      throw new Error(
        `Privatemode chat: ${this.model} is not valid or defined model for chat completion!`
      );

    const result = await LLMPerformanceMonitor.measureAsyncFunction(
      this.client.chat.completions.create({
        model: this.model,
        messages,
        temperature,
      })
    );

    if (
      !result.output.hasOwnProperty("choices") ||
      result.output.choices.length === 0
    )
      return null;

    return {

View on GitHub (pinned to 526360e320)

Solutions

  1. Set PRIVATEMODE_LLM_MODEL_PREF to a model the Privatemode server hosts (e.g. gemma-3-27b, qwen3-coder-30b-a3b, gpt-oss-120b) in server/.env.
  2. Pass an explicit modelPreference as the second constructor argument.
  3. Select a model in the AnythingLLM UI for that workspace.
  4. Confirm the chosen id is one the server actually serves via GET <base>/v1/models.

Example fix

// before
const llm = new PrivatemodeLLM(embedder); // no model -> undefined
await llm.getChatCompletion(messages, { temperature: 0.7 });

// after
const llm = new PrivatemodeLLM(embedder, process.env.PRIVATEMODE_LLM_MODEL_PREF || "gemma-3-27b");
await llm.getChatCompletion(messages, { temperature: 0.7 });
Defensive patterns

Strategy: validation

Validate before calling

function assertPrivatemodeModel(pref) {
  const model = pref || process.env.PRIVATEMODE_LLM_MODEL_PREF;
  if (!model) {
    throw new Error("No Privatemode model configured — set PRIVATEMODE_LLM_MODEL_PREF or pass modelPreference");
  }
  return model;
}
const model = assertPrivatemodeModel(modelPreference);
const llm = new PrivatemodeLLM(embedder, model);

Type guard

function isPrivatemodeModelSet(model) {
  return typeof model === "string" && model.trim().length > 0;
}

Try / catch

try {
  return await llm.getChatCompletion(messages, opts);
} catch (e) {
  if (/not valid or defined model/i.test(e.message)) {
    llm.model = process.env.PRIVATEMODE_LLM_MODEL_PREF || "gemma-3-27b";
    return llm.getChatCompletion(messages, opts);
  }
  throw e;
}

Prevention

When it happens

Trigger: Constructing PrivatemodeLLM without a modelPreference AND without PRIVATEMODE_LLM_MODEL_PREF set, then calling getChatCompletion. Unlike most providers here, there is no hardcoded fallback model id.

Common situations: Private mode selected as the workspace LLM but the model field left blank in the UI and PRIVATEMODE_LLM_MODEL_PREF not set in env; the model field was cleared during reconfiguration; an automation path that constructs the provider with `new PrivatemodeLLM(embedder)` and no second arg.

Related errors


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