Mintplex-Labs/anything-llm · error · Error
Invalid role. Allowed roles are: ${VALID_ROLES.join(", ")}
Error message
Invalid role. Allowed roles are: ${VALID_ROLES.join(", ")} What it means
Thrown by User.validations.role when the supplied role is not in the hard-coded set ['default','admin','manager']. The validator is called during User.create (line 130). The error message is a template literal that interpolates the allowed list, so the thrown string reads 'Invalid role. Allowed roles are: default, admin, manager'.
Source
Thrown at server/models/user.js:54
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(", ")}`
);
}
return String(role);
},
dailyMessageLimit: (dailyMessageLimit = null) => {
if (dailyMessageLimit === null) return null;
const limit = Number(dailyMessageLimit);
if (isNaN(limit) || limit < 1) {
throw new Error(
"Daily message limit must be null or a number greater than or equal to 1"
);
}
return limit;
},
bio: (bio = "") => {
if (!bio || typeof bio !== "string") return "";
if (bio.length > 1000)View on GitHub (pinned to 526360e320)
Solutions
- Use one of: 'default', 'admin', or 'manager'.
- Map any external/legacy role to the closest allowed value before calling User.create.
- Confirm frontend and backend role enums stay in sync.
Example fix
// before
User.create({ username, password, role: 'superuser' });
// after
User.create({ username, password, role: 'admin' }); Defensive patterns
Strategy: type-guard
Validate before calling
const ALLOWED_ROLES = ['default', 'admin', 'manager']; if (!ALLOWED_ROLES.includes(role)) role = 'default';
Type guard
const isValidRole = (r) => typeof r === 'string' && ['default', 'admin', 'manager'].includes(r);
Prevention
- Share a single role enum between frontend and backend.
- Default unknown roles to 'default' rather than rejecting, where the UX allows.
When it happens
Trigger: Creating a user with a role value outside the allowed set, e.g. 'superuser', 'owner', 'guest', or a typo like 'admn'.
Common situations: API client sends a role from a different auth vocabulary. A newer/older frontend version uses a role name not present in this backend. Migration/import carrying a legacy role string.
Related errors
- Username cannot be longer than 64 characters
- Username must be at least 2 characters
- Username must start with a lowercase letter and only contain
- Daily message limit must be null or a number greater than or
- Bio cannot be longer than 1,000 characters
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/4196e9fafd075fe6.
Report an issue: GitHub.