Mintplex-Labs/anything-llm · warning
Cannot update a preset to use a command that matches a syste
Error message
Cannot update a preset to use a command that matches a system command
What it means
Thrown by PUT /system/slash-command-presets/:slashCommandId when the submitted command, after normalization by SlashCommandPresets.formatCommand (lowercase, leading '/', invalid chars replaced with '-'), equals a key of VALID_COMMANDS (the built-in system commands loaded from server/utils/chats). The 400 response prevents user presets from shadowing reserved commands like /reset or /exit. This is a business-rule rejection, not a library error.
Source
Thrown at server/endpoints/system.js:1353
response.status(500).json({ message: "Internal server error" });
}
}
);
app.post(
"/system/slash-command-presets/:slashCommandId",
[validatedRequest, flexUserRoleValid([ROLES.all])],
async (request, response) => {
try {
const user = await userFromSession(request, response);
const { slashCommandId } = request.params;
const { command, prompt, description } = reqBody(request);
const formattedCommand = SlashCommandPresets.formatCommand(
String(command)
);
if (isReservedCommand(formattedCommand)) {
return response.status(400).json({
message:
"Cannot update a preset to use a command that matches a system command",
});
}
// Valid user running owns the preset if user session is valid.
const ownsPreset = await SlashCommandPresets.get({
userId: user?.id ?? null,
id: Number(slashCommandId),
});
if (!ownsPreset)
return response.status(404).json({ message: "Preset not found" });
const updates = {
command: formattedCommand,
prompt: String(prompt),
description: String(description),
};View on GitHub (pinned to 20f6d3546c)
Solutions
- Pick a different command name that is not one of the built-in system commands (check Object.keys(VALID_COMMANDS) in server/utils/chats/index.js).
- Add a prefix to make it unique, e.g. '/my-reset' instead of '/reset'.
- In the UI, validate the formatted command client-side against the system command list before enabling Save.
Example fix
// before
await fetch(`/system/slash-command-presets/${id}`, {
method: 'PUT',
body: JSON.stringify({ command: 'reset', prompt, description }),
});
// after
const formatted = `/${String(command).toLowerCase().replace(/[^a-z0-9_-]/g, '-')}`;
if (SYSTEM_COMMANDS.includes(formatted)) {
showToast(`"${formatted}" is reserved — choose another name`);
return;
}
await fetch(`/system/slash-command-presets/${id}`, {
method: 'PUT',
body: JSON.stringify({ command: formatted, prompt, description }),
}); Defensive patterns
Strategy: validation
Validate before calling
const CMD_REGEX = /[^a-zA-Z0-9_-]/g;
const formatCommand = (c) => `/${String(c).toLowerCase().replace(CMD_REGEX, '-')}`.replace(/^\/\/+/, '/');
const isSystemCommand = (c, systemCommands) => systemCommands.includes(formatCommand(c));
// systemCommands = Object.keys(VALID_COMMANDS) fetched from the backend/system list Type guard
function isSafePresetCommand(command, systemCommands) {
if (typeof command !== 'string' || command.length < 2) return false;
return !systemCommands.includes(formatCommand(command));
} Prevention
- Mirror the server's formatCommand normalization client-side so validation matches what the backend will compute.
- Keep the system-command list in shared config instead of duplicating it in the frontend.
- Suggest a prefixed name (e.g. /my-*) when the chosen command collides.
When it happens
Trigger: PUT /system/slash-command-presets/12 with body {"command": "reset", ...} — formatCommand turns it into "/reset", which exists in VALID_COMMANDS, so the endpoint returns 400 before touching the database. Any casing/spacing variant ("Reset", "/RESET", "re set") normalizes into the same collision.
Common situations: Renaming a preset to a short common word that happens to match a system command; importing preset packs from the community hub whose commands collide with built-ins; frontend forms that don't validate against the reserved list before submit.
Related errors
- Preset not found
- Failed to publish slash command: ${error.message}
- click requires <x> <y> coordinates
- type requires <text> argument
- key requires <key> argument (e.g. Enter, Tab, Escape)
AI-assisted analysis of Mintplex-Labs/anything-llm@20f6d3546c (2026-09-01).
Data as JSON: /api/errors/469815f579ee5761.
Report an issue: GitHub.