{"record":{"id":"be4a4fe1272e6f34","repo":"Mintplex-Labs/anything-llm","slug":"invalid-model-selection","errorCode":null,"errorMessage":"Invalid model selection","messagePattern":"Invalid model selection","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/LLMSelector/index.jsx","lineNumber":101,"sourceCode":"\n  async function handleSave() {\n    setSaving(true);\n    try {\n      setHasChanges(false);\n\n      const isRouter = selectedLLMProvider === \"anythingllm-router\";\n      if (isRouter && !selectedRouterId)\n        throw new Error(t(\"model-router.chat.select-router-error\"));\n\n      const updateData = isRouter\n        ? { chatProvider: selectedLLMProvider, router_id: selectedRouterId }\n        : {\n            chatProvider: selectedLLMProvider,\n            chatModel: validatedModelSelection(selectedLLMModel),\n          };\n\n      if (!isRouter && !updateData.chatModel)\n        throw new Error(t(\"model-router.chat.invalid-model\"));\n\n      const { message } = await Workspace.update(slug, updateData);\n\n      if (!!message) throw new Error(message);\n      window.dispatchEvent(new Event(SAVE_LLM_SELECTOR_EVENT));\n    } catch (error) {\n      console.error(error);\n      showToast(error.message, \"error\", { clear: true });\n    } finally {\n      setSaving(false);\n    }\n  }\n\n  const providerName =\n    WORKSPACE_LLM_PROVIDERS.find((p) => p.value === selectedLLMProvider)\n      ?.name || selectedLLMProvider;\n\n  if (loading) {","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/LLMSelector/index.jsx#L83-L119","documentation":"Companion guard for non-router providers: validatedModelSelection(selectedLLMModel) must yield a usable model id, and a falsy result throws the localized 'model-router.chat.invalid-model' message ('Invalid model selection') before Workspace.update is called. It catches the case where the provider is chosen but no concrete model is set.","triggerScenarios":"A non-router provider is selected while its model value is empty, a placeholder that normalizes to null, or the model list never loaded (missing credentials) so nothing was chosen.","commonSituations":"Provider lacks an API key so the model dropdown stayed empty; custom-model input cleared; switching providers quickly and saving before the new model list resolves; model value filtered out by validation.","solutions":["Select a concrete model for the chosen provider before saving","Add valid credentials for the provider so its model list populates, then pick a model","For custom-model providers, type a non-empty model id in the input"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const model = selectedLLMProvider === \"anythingllm-router\" ? null : validatedModelSelection(selectedLLMModel);\nconst canSave = selectedLLMProvider === \"anythingllm-router\" ? !!selectedRouterId : !!model;\n// disable Save when !canSave and flag the model dropdown","typeGuard":null,"tryCatchPattern":"try { await handleSave(); }\ncatch (e) { if (e.message === t(\"model-router.chat.invalid-model\")) highlightModelDropdown(); else throw e; }","preventionTips":["Require provider credentials to load the model list before enabling save","Normalize placeholder model values ('all', '') to null so validation fails early and visibly","Re-validate the model whenever the provider changes, not only on submit"],"tags":["llm-selector","model-selection","validation","frontend"],"backgroundTag":"invalid-model-selection","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}