{"record":{"id":"be2b0f303a24242a","repo":"Mintplex-Labs/anything-llm","slug":"system-prompt-variable-not-found","errorCode":null,"errorMessage":"System prompt variable not found","messagePattern":"System prompt variable not found","errorType":"exception","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/models/systemPromptVariables.js","lineNumber":203,"sourceCode":"        description: description ? String(description) : null,\n        type: type ? String(type) : \"static\",\n        userId: userId ? Number(userId) : null,\n      },\n    });\n  },\n\n  /**\n   * Updates a system prompt variable by its unique database ID\n   * @param {number} id\n   * @param {{ key: string, value: string, description: string }} data\n   * @returns {Promise<SystemPromptVariable>}\n   */\n  update: async function (id, { key, value, description = null }) {\n    if (!id || !key || !value) return null;\n    const existingRecord = await prisma.system_prompt_variables.findFirst({\n      where: { id: Number(id) },\n    });\n    if (!existingRecord) throw new Error(\"System prompt variable not found\");\n    await this._checkVariableKey(key, false);\n\n    return await prisma.system_prompt_variables.update({\n      where: { id: existingRecord.id },\n      data: {\n        key: String(key),\n        value: String(value),\n        description: description ? String(description) : null,\n      },\n    });\n  },\n\n  /**\n   * Deletes a system prompt variable by its unique database ID\n   * @param {number} id\n   * @returns {Promise<boolean>}\n   */\n  delete: async function (id = null) {","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/models/systemPromptVariables.js#L185-L221","documentation":"SystemPromptVariables.update(id, { key, value }) first does findFirst on system_prompt_variables by id; when no row matches it throws 'System prompt variable not found'. Note that update() silently returns null earlier when id, key, or value are falsy - so seeing this error means those were provided but the id has no database row.","triggerScenarios":"Updating a variable that was deleted in another session or by another admin; a numeric-looking string that Number() turns into NaN; an id copied from a different environment or database.","commonSituations":"Admin UI holding a stale variable list while another admin deletes entries; scripts replaying recorded ids against a fresh instance; id passed as an object or malformed string.","solutions":["List current variables to obtain valid ids before updating","Ensure the id param parses to a real integer (Number(id) is not NaN)","Treat this as a 404 in callers and refresh the variable list in the UI","If the variable was deleted intentionally, create it again instead of updating"],"exampleFix":"// before\nconst updated = await SystemPromptVariables.update(id, { key, value });\n\n// after\nconst existing = await SystemPromptVariables.get(id);\nif (!existing) throw new Error(`No system prompt variable ${id}`);\nconst updated = await SystemPromptVariables.update(existing.id, { key, value });","handlingStrategy":"validation","validationCode":"const { SystemPromptVariables } = require('../models/systemPromptVariables');\n\nconst existing = Number.isInteger(Number(id))\n  ? await SystemPromptVariables.get(Number(id))\n  : null;\nif (!existing) {\n  return res.status(404).json({ error: 'System prompt variable not found' });\n}\nawait SystemPromptVariables.update(existing.id, { key, value });","typeGuard":null,"tryCatchPattern":"try {\n  await SystemPromptVariables.update(id, { key, value });\n} catch (err) {\n  if (err.message === 'System prompt variable not found') {\n    // refresh the list the UI shows and return 404\n  } else throw err;\n}","preventionTips":["Fetch the variable by id before attempting an update; treat missing ids as 404s","Re-fetch the variable list when the edit view opens so concurrent deletes surface early","Never pass malformed ids; validate Number(id) is an integer first"],"tags":["system-prompt","lookup","anythingllm"],"backgroundTag":"record-not-found","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}