{"record":{"id":"454b693443038b3d","repo":"Mintplex-Labs/anything-llm","slug":"key-must-be-at-least-3-characters","errorCode":null,"errorMessage":"Key must be at least 3 characters","messagePattern":"Key must be at least 3 characters","errorType":"validation","errorClass":null,"httpStatus":500,"severity":"warning","filePath":"server/models/systemPromptVariables.js","lineNumber":363,"sourceCode":"      console.error(\"Error in expandSystemPromptVariables:\", error);\n      return str;\n    }\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":345,"sourceCodeEnd":376,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/models/systemPromptVariables.js#L345-L376","documentation":"Validation rule in SystemPromptVariables._checkVariableKey: the proposed variable key is shorter than the required 3-character minimum, which is treated as too short to be a meaningful, unambiguous substitution key.","triggerScenarios":"Using short abbreviations ('id', 'ui', 'x') as keys; keys built from single-letter flags; trimmed input that collapsed to one or two characters.","commonSituations":"Compact internal naming conventions colliding with the minimum; forms where the user typed a very short identifier; programmatic keys derived from enum codes like 'A' or 'OK'.","solutions":["Expand the abbreviation to at least 3 characters ('id' -> 'user_id')","When generating keys from codes, add a fixed prefix ('x_a')","Validate minimum length in the UI before submission"],"exampleFix":"// before\nSystemPromptVariables.create({ key: 'id', value: '123' }); // throws\n\n// after\nSystemPromptVariables.create({ key: 'user_id', value: '123' });","handlingStrategy":"validation","validationCode":"const MIN_KEY_LEN = 3;\n\nif (typeof key !== 'string' || key.length < MIN_KEY_LEN) {\n  return res.status(400).json({ error: `Key must be at least ${MIN_KEY_LEN} characters` });\n}","typeGuard":null,"tryCatchPattern":"try {\n  await SystemPromptVariables.create({ key, value });\n} catch (err) {\n  if (/at least 3 characters/.test(err.message)) {\n    return res.status(400).json({ error: 'Key too short; expand the abbreviation' });\n  }\n  throw err;\n}","preventionTips":["Avoid one- and two-letter identifiers; prefer descriptive keys","When deriving keys from codes, add a fixed prefix so length >= 3","Validate minimum length client-side before submission"],"tags":["system-prompt","validation","length-limit"],"backgroundTag":"field-too-short","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}