{"record":{"id":"bb0298d0dd9e511f","repo":"Mintplex-Labs/anything-llm","slug":"key-must-be-less-than-255-characters","errorCode":null,"errorMessage":"Key must be less than 255 characters","messagePattern":"Key must be less than 255 characters","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/models/systemPromptVariables.js","lineNumber":362,"sourceCode":"    } catch (error) {\n      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":344,"sourceCodeEnd":376,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/models/systemPromptVariables.js#L344-L376","documentation":"Thrown by SystemPromptVariables._checkVariableKey when key.length > 255. Enforces the storage column width for the system_prompt_variables.key field. Runs on both create and update because _checkVariableKey is invoked before either prisma write.","triggerScenarios":"POST/PUT /system/prompt-variables with a key string longer than 255 characters after it passes the character-class regex.","commonSituations":"Programmatically generated keys (hashed names, concatenated identifiers) exceeding the limit. Pasting a long identifier from another system without truncation.","solutions":["Shorten the key to 255 characters or fewer.","If a long source identifier is unavoidable, hash or abbreviate it before using as the key.","Enforce a max-length check in the submitting form."],"exampleFix":"// before\nSystemPromptVariables.create({ key: veryLongGeneratedString, value: '...' });\n// after\nconst key = generatedString.slice(0, 255);\nSystemPromptVariables.create({ key, value: '...' });","handlingStrategy":"validation","validationCode":"const MAX_KEY = 255;\nif (typeof key === 'string' && key.length > MAX_KEY) {\n  key = key.slice(0, MAX_KEY);\n}","typeGuard":"const isWithinKeyLimit = (k) => typeof k === 'string' && k.length <= 255;","tryCatchPattern":null,"preventionTips":["Set maxlength=255 on the key input.","For generated keys, hash long source strings before use."],"tags":["validation","system-prompt-variables","length-limit"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}