{"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":"Error","httpStatus":null,"severity":"error","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/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/models/systemPromptVariables.js#L349-L376","documentation":"Thrown by SystemPromptVariables._checkVariableKey when key starts with 'system.'. The 'system.' namespace is reserved for built-in system variables supplied by the platform during prompt expansion, so a user-defined static variable with that prefix is rejected to avoid collisions.","triggerScenarios":"POST/PUT /system/prompt-variables with a key like 'system.foo', 'system.context', or 'system.date'.","commonSituations":"An admin assumes 'system.' is the conventional prefix for platform-level variables and tries to register one.","solutions":["Rename the key to drop the 'system.' prefix (e.g. 'system_context' or 'app_context').","Use the built-in 'system.*' variables instead of redefining them as static entries."],"exampleFix":"// before\nSystemPromptVariables.create({ key: 'system.context', value: '...' });\n// after\nSystemPromptVariables.create({ key: 'app_context', value: '...' });","handlingStrategy":"validation","validationCode":"if (typeof key === 'string' && key.startsWith('system.')) {\n  throw new Error(\"Keys cannot use the reserved 'system.' prefix\");\n}","typeGuard":"const isNonReservedKey = (k) => typeof k === 'string' && !k.startsWith('system.') && !k.startsWith('user.');","tryCatchPattern":null,"preventionTips":["Surface reserved-prefix rules next to the key field.","Reuse the built-in system.* variables instead of redefining them."],"tags":["validation","system-prompt-variables","reserved-namespace"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}