Mintplex-Labs/anything-llm · error · Error

Key cannot start with 'user.'

Error message

Key cannot start with 'user.'

What it means

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.

Source

Thrown at server/models/systemPromptVariables.js:365

    }
  },

  /**
   * Internal function to check if a variable key is valid
   * @param {string} key
   * @param {boolean} checkExisting
   * @returns {Promise<boolean>}
   */
  _checkVariableKey: async function (key = null, checkExisting = true) {
    if (!key) throw new Error("Key is required");
    if (typeof key !== "string") throw new Error("Key must be a string");
    if (!/^[a-zA-Z0-9_]+$/.test(key))
      throw new Error("Key must contain only letters, numbers and underscores");
    if (key.length > 255)
      throw new Error("Key must be less than 255 characters");
    if (key.length < 3) throw new Error("Key must be at least 3 characters");
    if (key.startsWith("user."))
      throw new Error("Key cannot start with 'user.'");
    if (key.startsWith("system."))
      throw new Error("Key cannot start with 'system.'");
    if (checkExisting && (await this.get(key)) !== null)
      throw new Error("System prompt variable with this key already exists");

    return true;
  },
};

module.exports = { SystemPromptVariables };

View on GitHub (pinned to 526360e320)

Solutions

  1. Rename the key so it does not start with 'user.' (e.g. 'user_name' or 'currentUser').
  2. If you genuinely need user attributes, rely on the built-in dynamic 'user.*' variables rather than defining a static one.

Example fix

// before
SystemPromptVariables.create({ key: 'user.email', value: '...' });
// after
SystemPromptVariables.create({ key: 'contact_email', value: '...' });
Defensive patterns

Strategy: validation

Validate before calling

const RESERVED = ['user.', 'system.'];
const safeKey = RESERVED.some(p => key.startsWith(p))
  ? key.replace('.', '_')
  : key;

Type guard

const isNonReservedKey = (k) => typeof k === 'string' && !k.startsWith('user.') && !k.startsWith('system.');

Prevention

When it happens

Trigger: POST/PUT /system/prompt-variables with a key like 'user.name', 'user.email', or 'user.foo'.

Common situations: An admin tries to define a custom variable to surface user attributes and intuitively picks the 'user.' prefix.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/68bdbd1c0b881b50. Report an issue: GitHub.