{"record":{"id":"687c3e2707712e3e","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-update-default-system-prompt","errorCode":null,"errorMessage":"Failed to update default system prompt.","messagePattern":"Failed to update default system prompt\\.","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/endpoints/system.js","lineNumber":907,"sourceCode":"        console.error(\"Error fetching default system prompt:\", error);\n        response\n          .status(500)\n          .json({ success: false, message: \"Internal server error\" });\n      }\n    }\n  );\n\n  app.post(\n    \"/system/default-system-prompt\",\n    [validatedRequest, flexUserRoleValid([ROLES.admin])],\n    async (request, response) => {\n      try {\n        const { defaultSystemPrompt } = reqBody(request);\n        const { success, error } = await SystemSettings.updateSettings({\n          default_system_prompt: defaultSystemPrompt,\n        });\n        if (!success)\n          throw new Error(\n            error.message || \"Failed to update default system prompt.\"\n          );\n        response.status(200).json({\n          success: true,\n          message: \"Default system prompt updated successfully.\",\n        });\n      } catch (error) {\n        console.error(\"Error updating default system prompt:\", error);\n        response.status(500).json({\n          success: false,\n          message: error.message || \"Internal server error\",\n        });\n      }\n    }\n  );\n\n  app.delete(\n    \"/system/remove-pfp\",","sourceCodeStart":889,"sourceCodeEnd":925,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/20f6d3546c1938bfea1ad304f58a592dddcc5948/server/endpoints/system.js#L889-L925","documentation":"Thrown by POST /system/default-system-prompt (admin-only) when SystemSettings.updateSettings({ default_system_prompt }) reports success:false. The settings pipeline validates the field (non-empty string required — non-strings/empty become null), filters to supported fields, and can fail on database write errors; the thrown message is error.message or the literal 'Failed to update default system prompt.' when no message exists. Returned to the client as HTTP 500.","triggerScenarios":"POSTing a defaultSystemPrompt that is not a non-empty string (null, empty string) so the field validator nulls it and the update fails; sending the field when the running server version/DB schema doesn't support it; transient or persistent DB errors during the settings write (locked SQLite file, failed Postgres connection).","commonSituations":"Automation scripts PUT/POSTing the whole settings object including an empty prompt; instances where the storage folder permissions broke (docker volumes); older snapshots restored into a newer schema.","solutions":["Send a non-empty string body { defaultSystemPrompt: 'You are...' } and confirm you are POSTing to /system/default-system-prompt as an admin","Check the server console — the handler logs 'Error updating default system prompt:' with the underlying error.message which names the real cause (DB write, validation)","Fix storage/DB access if logs show write failures (permissions on the anythingllm storage dir, reachable DB, not-locked SQLite)","If you actually want to clear the prompt, check for a dedicated delete/reset route or send the documented sane default text instead of an empty string"],"exampleFix":"// before\nawait api.post('/system/default-system-prompt', { defaultSystemPrompt: '' });\n// after\nawait api.post('/system/default-system-prompt', { defaultSystemPrompt: 'You are a helpful assistant.' });","handlingStrategy":"validation","validationCode":"function isValidSystemPrompt(p) { return typeof p === 'string' && p.trim().length > 0; }\nif (!isValidSystemPrompt(payload.defaultSystemPrompt)) throw new Error('defaultSystemPrompt must be a non-empty string');","typeGuard":"function isNonEmptyPrompt(p: unknown): p is string { return typeof p === 'string' && p.trim().length > 0; }","tryCatchPattern":"try { await api.post('/system/default-system-prompt', { defaultSystemPrompt }); } catch (e) { if (/Failed to update default system prompt/.test(e.message)) { /* inspect server console 'Error updating default system prompt:' for the DB/validation root cause */ } else throw e; }","preventionTips":["Always send a non-empty string; empty/null is rejected by the field validator","Check server logs on this failure — the underlying error.message names the real cause","Confirm admin auth (validatedRequest + admin role) before calling, 403s are a separate failure mode"],"tags":["anythingllm","system-settings","system-prompt","admin","persistence"],"backgroundTag":"settings-update-failed","analyzedSha":"20f6d3546c1938bfea1ad304f58a592dddcc5948","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}