Mintplex-Labs/anything-llm · error · Error
Key must be less than 255 characters
Error message
Key must be less than 255 characters
What it means
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.
Source
Thrown at server/models/systemPromptVariables.js:362
} catch (error) {
console.error("Error in expandSystemPromptVariables:", error);
return str;
}
},
/**
* 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
- 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.
Example fix
// before
SystemPromptVariables.create({ key: veryLongGeneratedString, value: '...' });
// after
const key = generatedString.slice(0, 255);
SystemPromptVariables.create({ key, value: '...' }); Defensive patterns
Strategy: validation
Validate before calling
const MAX_KEY = 255;
if (typeof key === 'string' && key.length > MAX_KEY) {
key = key.slice(0, MAX_KEY);
} Type guard
const isWithinKeyLimit = (k) => typeof k === 'string' && k.length <= 255;
Prevention
- Set maxlength=255 on the key input.
- For generated keys, hash long source strings before use.
When it happens
Trigger: POST/PUT /system/prompt-variables with a key string longer than 255 characters after it passes the character-class regex.
Common situations: Programmatically generated keys (hashed names, concatenated identifiers) exceeding the limit. Pasting a long identifier from another system without truncation.
Related errors
- Key is required
- Key must contain only letters, numbers and underscores
- Key cannot start with 'user.'
- Key cannot start with 'system.'
- System prompt variable with this key already exists
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/bb0298d0dd9e511f.
Report an issue: GitHub.