Mintplex-Labs/anything-llm · warning
Key must be at least 3 characters
Error message
Key must be at least 3 characters
What it means
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.
Source
Thrown at server/models/systemPromptVariables.js:363
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 3aec848f28)
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
Example fix
// before
SystemPromptVariables.create({ key: 'id', value: '123' }); // throws
// after
SystemPromptVariables.create({ key: 'user_id', value: '123' }); Defensive patterns
Strategy: validation
Validate before calling
const MIN_KEY_LEN = 3;
if (typeof key !== 'string' || key.length < MIN_KEY_LEN) {
return res.status(400).json({ error: `Key must be at least ${MIN_KEY_LEN} characters` });
} Try / catch
try {
await SystemPromptVariables.create({ key, value });
} catch (err) {
if (/at least 3 characters/.test(err.message)) {
return res.status(400).json({ error: 'Key too short; expand the abbreviation' });
}
throw err;
} Prevention
- 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
When it happens
Trigger: Using short abbreviations ('id', 'ui', 'x') as keys; keys built from single-letter flags; trimmed input that collapsed to one or two characters.
Common situations: 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'.
Related errors
- Key must be less than 255 characters
- Key is required
- Key must be a string
- Key must contain only letters, numbers and underscores
- Key cannot start with 'user.'
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/454b693443038b3d.
Report an issue: GitHub.