{"record":{"id":"78674e91102bb7f0","repo":"Mintplex-Labs/anything-llm","slug":"privatemode-chat-this-model-is-not-valid-or-de","errorCode":null,"errorMessage":"Privatemode chat: ${this.model} is not valid or defined model for chat completion!","messagePattern":"Privatemode chat: (.+?) is not valid or defined model for chat completion!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/privatemode/index.js","lineNumber":145,"sourceCode":"    attachments = [],\n  }) {\n    const prompt = {\n      role: \"system\",\n      content: `${systemPrompt}${this.#appendContext(contextTexts)}`,\n    };\n    return [\n      prompt,\n      ...formatChatHistory(chatHistory, this.#generateContent),\n      {\n        role: \"user\",\n        content: this.#generateContent({ userPrompt, attachments }),\n      },\n    ];\n  }\n\n  async getChatCompletion(messages = null, { temperature = 0.7 }) {\n    if (!this.model)\n      throw new Error(\n        `Privatemode chat: ${this.model} is not valid or defined model for chat completion!`\n      );\n\n    const result = await LLMPerformanceMonitor.measureAsyncFunction(\n      this.client.chat.completions.create({\n        model: this.model,\n        messages,\n        temperature,\n      })\n    );\n\n    if (\n      !result.output.hasOwnProperty(\"choices\") ||\n      result.output.choices.length === 0\n    )\n      return null;\n\n    return {","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/privatemode/index.js#L127-L163","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Pass an explicit modelPreference as the second constructor argument.","Select a model in the AnythingLLM UI for that workspace.","Confirm the chosen id is one the server actually serves via GET <base>/v1/models."],"exampleFix":"// before\nconst llm = new PrivatemodeLLM(embedder); // no model -> undefined\nawait llm.getChatCompletion(messages, { temperature: 0.7 });\n\n// after\nconst llm = new PrivatemodeLLM(embedder, process.env.PRIVATEMODE_LLM_MODEL_PREF || \"gemma-3-27b\");\nawait llm.getChatCompletion(messages, { temperature: 0.7 });","handlingStrategy":"validation","validationCode":"function assertPrivatemodeModel(pref) {\n  const model = pref || process.env.PRIVATEMODE_LLM_MODEL_PREF;\n  if (!model) {\n    throw new Error(\"No Privatemode model configured — set PRIVATEMODE_LLM_MODEL_PREF or pass modelPreference\");\n  }\n  return model;\n}\nconst model = assertPrivatemodeModel(modelPreference);\nconst llm = new PrivatemodeLLM(embedder, model);","typeGuard":"function isPrivatemodeModelSet(model) {\n  return typeof model === \"string\" && model.trim().length > 0;\n}","tryCatchPattern":"try {\n  return await llm.getChatCompletion(messages, opts);\n} catch (e) {\n  if (/not valid or defined model/i.test(e.message)) {\n    llm.model = process.env.PRIVATEMODE_LLM_MODEL_PREF || \"gemma-3-27b\";\n    return llm.getChatCompletion(messages, opts);\n  }\n  throw e;\n}","preventionTips":["Privatemode has no default model — always set PRIVATEMODE_LLM_MODEL_PREF in env or pass modelPreference.","Validate at boot that the chosen id is in GET <base>/v1/models.","Treat a blank model field in the UI as a hard error, not a silent skip.","Document the supported ids (gemma-3-27b, qwen3-coder-30b-a3b, gpt-oss-120b) next to the setting."],"tags":["validation","model-selection","llm-provider","privatemode","chat-completion"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}