Mintplex-Labs/anything-llm · error
System prompt variable not found
Error message
System prompt variable not found
What it means
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.
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
Example fix
// before
const updated = await SystemPromptVariables.update(id, { key, value });
// after
const existing = await SystemPromptVariables.get(id);
if (!existing) throw new Error(`No system prompt variable ${id}`);
const updated = await SystemPromptVariables.update(existing.id, { key, value }); Defensive patterns
Strategy: validation
Validate before calling
const { SystemPromptVariables } = require('../models/systemPromptVariables');
const existing = Number.isInteger(Number(id))
? await SystemPromptVariables.get(Number(id))
: null;
if (!existing) {
return res.status(404).json({ error: 'System prompt variable not found' });
}
await SystemPromptVariables.update(existing.id, { key, value }); Try / catch
try {
await SystemPromptVariables.update(id, { key, value });
} catch (err) {
if (err.message === 'System prompt variable not found') {
// refresh the list the UI shows and return 404
} else throw err;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- Could not find a document by id
- Failed to update default system prompt.
- Run not found
- Bad Request
- Community hub bundle downloads are limited to verified…
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/be2b0f303a24242a.
Report an issue: GitHub.
Appendix: source
Thrown at server/models/systemPromptVariables.js:203
description: description ? String(description) : null,
type: type ? String(type) : "static",
userId: userId ? Number(userId) : null,
},
});
},
/**
* Updates a system prompt variable by its unique database ID
* @param {number} id
* @param {{ key: string, value: string, description: string }} data
* @returns {Promise<SystemPromptVariable>}
*/
update: async function (id, { key, value, description = null }) {
if (!id || !key || !value) return null;
const existingRecord = await prisma.system_prompt_variables.findFirst({
where: { id: Number(id) },
});
if (!existingRecord) throw new Error("System prompt variable not found");
await this._checkVariableKey(key, false);
return await prisma.system_prompt_variables.update({
where: { id: existingRecord.id },
data: {
key: String(key),
value: String(value),
description: description ? String(description) : null,
},
});
},
/**
* Deletes a system prompt variable by its unique database ID
* @param {number} id
* @returns {Promise<boolean>}
*/
delete: async function (id = null) {View on GitHub (pinned to 3aec848f28)