{"record":{"id":"68bdbd1c0b881b50","repo":"Mintplex-Labs/anything-llm","slug":"key-cannot-start-with-user","errorCode":null,"errorMessage":"Key cannot start with 'user.'","messagePattern":"Key cannot start with 'user\\.'","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/models/systemPromptVariables.js","lineNumber":365,"sourceCode":"    }\n  },\n\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":347,"sourceCodeEnd":376,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/models/systemPromptVariables.js#L347-L376","documentation":"Thrown by SystemPromptVariables._checkVariableKey when key starts with 'user.'. The 'user.' namespace is reserved for dynamic user-scoped variables injected at prompt-expansion time (see expandSystemPromptVariables), so a static variable with that prefix would shadow or collide with the dynamic one.","triggerScenarios":"POST/PUT /system/prompt-variables with a key like 'user.name', 'user.email', or 'user.foo'.","commonSituations":"An admin tries to define a custom variable to surface user attributes and intuitively picks the 'user.' prefix.","solutions":["Rename the key so it does not start with 'user.' (e.g. 'user_name' or 'currentUser').","If you genuinely need user attributes, rely on the built-in dynamic 'user.*' variables rather than defining a static one."],"exampleFix":"// before\nSystemPromptVariables.create({ key: 'user.email', value: '...' });\n// after\nSystemPromptVariables.create({ key: 'contact_email', value: '...' });","handlingStrategy":"validation","validationCode":"const RESERVED = ['user.', 'system.'];\nconst safeKey = RESERVED.some(p => key.startsWith(p))\n  ? key.replace('.', '_')\n  : key;","typeGuard":"const isNonReservedKey = (k) => typeof k === 'string' && !k.startsWith('user.') && !k.startsWith('system.');","tryCatchPattern":null,"preventionTips":["Document the reserved namespaces in the variable-management UI.","Block the 'user.' and 'system.' prefixes client-side with an inline hint."],"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"}