{"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":null,"httpStatus":500,"severity":"warning","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/3aec848f2885144aa8f1e53b9731a04310d5d558/server/models/systemPromptVariables.js#L344-L376","documentation":"Validation guard in _checkVariableKey: the supplied system-prompt variable key exceeds the 255-character limit enforced to keep keys safe for storage and template rendering. Fires when caller passes an overly long key string.","triggerScenarios":"Keys generated by concatenating structured data (JSON.stringify of a config section) into the key; hashed or base64-encoded values used as keys; long descriptive labels pasted into the key field.","commonSituations":"Programmatic key generation without a length cap; importing external metadata wholesale as keys; test fixtures with oversized identifiers.","solutions":["Cap generated keys with a length limit (e.g. key.slice(0, 255)) and ensure uniqueness within it","Move long text into the variable's `value` field, keeping the key a short identifier","Hash or slugify long sources before using them as keys"],"exampleFix":"// before\nconst key = `section_${JSON.stringify(section)}`; // easily exceeds 255 chars\n\n// after\nconst key = `section_${slugify(section.name).slice(0, 40)}`;","handlingStrategy":"validation","validationCode":"const MAX_KEY_LEN = 255;\n\nif (typeof key === 'string' && key.length > MAX_KEY_LEN) {\n  return res.status(400).json({ error: `Key must be at most ${MAX_KEY_LEN} characters` });\n}","typeGuard":null,"tryCatchPattern":"try {\n  await SystemPromptVariables.create({ key, value });\n} catch (err) {\n  if (/less than 255 characters/.test(err.message)) {\n    return res.status(400).json({ error: 'Key too long; shorten it' });\n  }\n  throw err;\n}","preventionTips":["Treat keys as short identifiers; put long text in the value field","Cap generated keys with slice(0, 255) plus a uniqueness check","Add maxlength attributes on key inputs in the UI"],"tags":["system-prompt","validation","length-limit"],"backgroundTag":"field-length-limit-exceeded","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}