Mintplex-Labs/anything-llm · error

${response.error || "Failed to create system prompt"}

Error message

${response.error || "Failed to create system prompt"}

What it means

Thrown from `createSystemPrompt` on a non-ok `POST /api/community-hub/system-prompt/create`. Reads `response.error`, falling back to 'Failed to create system prompt'. Validation 4xx is the most common cause: the prompt payload (name, visibility, prompt text, tags) must satisfy the hub schema.

Source

Thrown at frontend/src/models/communityHub.js:176

   * Create a new system prompt in the community hub
   * @param {Object} data - The system prompt data
   * @param {string} data.name - The name of the prompt
   * @param {string} data.description - The description of the prompt
   * @param {string} data.prompt - The actual system prompt text
   * @param {string[]} data.tags - Array of tags
   * @param {string} data.visibility - Either 'public' or 'private'
   * @returns {Promise<{success: boolean, error: string | null}>}
   */
  createSystemPrompt: async (data) => {
    return await fetch(`${API_BASE}/community-hub/system-prompt/create`, {
      method: "POST",
      headers: baseHeaders(),
      body: JSON.stringify(data),
    })
      .then(async (res) => {
        const response = await res.json();
        if (!res.ok)
          throw new Error(response.error || "Failed to create system prompt");
        return { success: true, error: null, itemId: response.item?.id };
      })
      .catch((e) => ({
        success: false,
        error: e.message,
      }));
  },

  /**
   * Create a new agent flow in the community hub
   * @param {Object} data - The agent flow data
   * @returns {Promise<{success: boolean, error: string | null}>}
   */
  createAgentFlow: async (data) => {
    return await fetch(`${API_BASE}/community-hub/agent-flow/create`, {
      method: "POST",
      headers: baseHeaders(),
      body: JSON.stringify(data),

View on GitHub (pinned to 526360e320)

Solutions

  1. Validate the payload shape client-side (non-empty name+prompt, visibility ∈ {public,private}, tags array).
  2. Read `error` from the returned `{ success, error }` for the precise reason.
  3. On 401 re-authenticate; on 409 rename the prompt.
  4. Trim fields and enforce tag count/length limits before posting.

Example fix

// before
await CommunityHub.createSystemPrompt(formData);

// after
const payload = {
  name: String(formData.name).trim(),
  prompt: String(formData.prompt).trim(),
  visibility: ['public','private'].includes(formData.visibility) ? formData.visibility : 'private',
  tags: Array.isArray(formData.tags) ? formData.tags.slice(0, 10) : [],
};
if (!payload.name || !payload.prompt) throw new Error('Name and prompt are required');
const { success, error } = await CommunityHub.createSystemPrompt(payload);
if (!success) throw new Error(error || 'Failed to create system prompt');
Defensive patterns

Strategy: validation

Validate before calling

function validateSystemPromptPayload(data) {
  const name = String(data?.name || '').trim();
  const prompt = String(data?.prompt || '').trim();
  const visibility = data?.visibility;
  if (!name) throw new Error('System prompt name is required');
  if (!prompt) throw new Error('System prompt text is required');
  if (!['public','private'].includes(visibility)) throw new Error("visibility must be 'public' or 'private'");
  if (!Array.isArray(data?.tags)) throw new Error('tags must be an array');
}

Type guard

function isSystemPromptPayload(v) {
  return !!v && typeof v === 'string' && typeof v.name === 'string' && typeof v.prompt === 'string'
    && ['public','private'].includes(v.visibility) && Array.isArray(v.tags);
}

Try / catch

const { success, error, itemId } = await CommunityHub.createSystemPrompt(data);
if (!success) showToast(error || 'Failed to create system prompt');

Prevention

When it happens

Trigger: Missing required fields (name/prompt/visibility), invalid `visibility` value (not 'public'/'private'), tags not an array or over the limit, 401 non-admin, 409 duplicate name, 500 persistence failure.

Common situations: Submitting an incomplete form; visibility typo; too many/oversized tags; session expired before submit.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/a8db93bb243b4b99. Report an issue: GitHub.