Mintplex-Labs/anything-llm · error · Error
Username cannot be longer than 64 characters
Error message
Username cannot be longer than 64 characters
What it means
Thrown by User.validations.username when the stringified input exceeds 64 characters. The validator runs during User.create (line 122) and via the admin user-update endpoint (system.js:1252). It enforces the storage width of the users.username column and keeps names displayable.
Source
Thrown at server/models/user.js:39
"password",
"pfpFilename",
"role",
"suspended",
"dailyMessageLimit",
"bio",
],
validations: {
/**
* Unix-style username regex:
* - Must start with a lowercase letter
* - Can contain lowercase letters, digits, underscores, hyphens, @ signs, and periods
* - 2-64 characters long
*/
username: (newValue = "") => {
try {
const username = String(newValue);
if (username.length > 64)
throw new Error("Username cannot be longer than 64 characters");
if (username.length < 2)
throw new Error("Username must be at least 2 characters");
if (!User.usernameRegex.test(username))
throw new Error(
"Username must start with a lowercase letter and only contain lowercase letters, numbers, underscores, hyphens, and periods"
);
return username;
} catch (e) {
throw new Error(e.message);
}
},
role: (role = "default") => {
const VALID_ROLES = ["default", "admin", "manager"];
if (!VALID_ROLES.includes(role)) {
throw new Error(
`Invalid role. Allowed roles are: ${VALID_ROLES.join(", ")}`
);
}View on GitHub (pinned to 526360e320)
Solutions
- Truncate or reformat the username to 64 characters or fewer before submitting.
- In SSO provisioning, map the long external identifier to a short handle and store the original elsewhere.
- Add a maxlength=64 attribute on the username input in the UI.
Example fix
// before const validated = User.validations.username(longExternalName); // after const validated = User.validations.username(longExternalName.slice(0, 64));
Defensive patterns
Strategy: validation
Validate before calling
if (typeof username === 'string' && username.length > 64) {
username = username.slice(0, 64);
} Type guard
const isUsernameLengthOk = (u) => typeof u === 'string' && u.length >= 2 && u.length <= 64;
Prevention
- Set maxlength=64 on the username input.
- In SSO provisioning, shorten long external identifiers to a handle.
When it happens
Trigger: Creating a user (POST) or updating a username (PUT to the admin user endpoint) with a value longer than 64 characters.
Common situations: An external IdP/SSO provisioner passes a long email-style or DN-derived username. Bulk import from another system with lax limits. A script concatenates first/last names past the cap.
Related errors
- Username must be at least 2 characters
- Bio cannot be longer than 1,000 characters
- Key must be less than 255 characters
- Username must start with a lowercase letter and only contain
- Invalid role. Allowed roles are: ${VALID_ROLES.join(", ")}
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/e55718f8715390b8.
Report an issue: GitHub.