{"record":{"id":"9055d63728da0b1e","repo":"Mintplex-Labs/anything-llm","slug":"key-cannot-start-with-system","errorCode":null,"errorMessage":"Key cannot start with 'system.'","messagePattern":"Key cannot start with 'system\\.'","errorType":"validation","errorClass":null,"httpStatus":500,"severity":"warning","filePath":"server/models/systemPromptVariables.js","lineNumber":367,"sourceCode":"\n  /**\n   * Internal function to check if a variable key is valid\n   * @param {string} key\n   * @param {boolean} checkExisting\n   * @returns {Promise<boolean>}\n   */\n  _checkVariableKey: async function (key = null, checkExisting = true) {\n    if (!key) throw new Error(\"Key is required\");\n    if (typeof key !== \"string\") throw new Error(\"Key must be a string\");\n    if (!/^[a-zA-Z0-9_]+$/.test(key))\n      throw new Error(\"Key must contain only letters, numbers and underscores\");\n    if (key.length > 255)\n      throw new Error(\"Key must be less than 255 characters\");\n    if (key.length < 3) throw new Error(\"Key must be at least 3 characters\");\n    if (key.startsWith(\"user.\"))\n      throw new Error(\"Key cannot start with 'user.'\");\n    if (key.startsWith(\"system.\"))\n      throw new Error(\"Key cannot start with 'system.'\");\n    if (checkExisting && (await this.get(key)) !== null)\n      throw new Error(\"System prompt variable with this key already exists\");\n\n    return true;\n  },\n};\n\nmodule.exports = { SystemPromptVariables };\n","sourceCodeStart":349,"sourceCodeEnd":376,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/models/systemPromptVariables.js#L349-L376","documentation":"Keys starting with 'system.' are reserved for the system-defined expansion namespace; custom variables may not shadow them. As with 'user.', a dotted key is rejected earlier by the character-set check, so this guard is defense-in-depth for the reserved namespace in the current validation order.","triggerScenarios":"Attempting to define 'system.prompt' or 'system.date' as a custom variable; copying a built-in template placeholder verbatim as a key when creating a variable.","commonSituations":"Trying to override built-in system expansion values; importing variable sets from other tools that use dotted system namespaces.","solutions":["Pick a key outside the reserved namespace, e.g. 'app_version' instead of 'system.version'","Use underscores for pseudo-namespacing: 'system_date' still starts with 'system_' not 'system.' and passes - prefer a clearer distinct name like 'runtime_date'","Document reserved prefixes for your team so they are not attempted"],"exampleFix":"// before\nSystemPromptVariables.create({ key: 'system.date', value: '2026-01-01' }); // reserved prefix\n\n// after\nSystemPromptVariables.create({ key: 'fallback_date', value: '2026-01-01' });","handlingStrategy":"validation","validationCode":"const RESERVED_PREFIXES = ['user.', 'system.'];\n\nfunction usesReservedPrefix(key) {\n  return typeof key === 'string' && RESERVED_PREFIXES.some((p) => key.startsWith(p));\n}\n\nif (usesReservedPrefix(key)) {\n  return res.status(400).json({ error: 'Keys may not start with user. or system.' });\n}","typeGuard":null,"tryCatchPattern":"try {\n  await SystemPromptVariables.create({ key, value });\n} catch (err) {\n  if (/cannot start with/.test(err.message)) {\n    return res.status(400).json({ error: 'Reserved namespace; rename the key' });\n  }\n  throw err;\n}","preventionTips":["Never copy a built-in {{system.*}} placeholder verbatim as a custom key","Namespace custom keys with underscores and a distinct project prefix","Share the reserved-prefix list with anyone authoring prompt templates"],"tags":["system-prompt","validation","reserved-name"],"backgroundTag":"reserved-keyword-conflict","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"}