{"record":{"id":"963e86491dad1dc2","repo":"Mintplex-Labs/anything-llm","slug":"content-must-be-a-non-empty-string","errorCode":null,"errorMessage":"Content must be a non-empty string","messagePattern":"Content must be a non-empty string","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"server/models/memory.js","lineNumber":40,"sourceCode":"const Memory = {\n  GLOBAL_LIMIT: 5,\n  WORKSPACE_LIMIT: 20,\n  MAX_INJECTED_WORKSPACE_LIMIT: 5,\n  VALID_SCOPES: [\"workspace\", \"global\"],\n\n  validations: {\n    id: (v) => toInt(v),\n    userId: (v = null) => (v === null || v === undefined ? null : toInt(v)),\n    workspaceId: (v = null) =>\n      v === null || v === undefined ? null : toInt(v),\n    scope: (v = \"workspace\") => {\n      if (!Memory.VALID_SCOPES.includes(v))\n        throw new Error(`Invalid scope: ${JSON.stringify(v)}`);\n      return v;\n    },\n    content: (v) => {\n      if (typeof v !== \"string\" || v.trim().length === 0)\n        throw new Error(\"Content must be a non-empty string\");\n      return v;\n    },\n  },\n\n  /**\n   * List a user's workspace-scoped memories, newest first.\n   * @param {number|null} userId\n   * @param {number} workspaceId\n   * @returns {Promise<Memory[]>}\n   */\n  forUserWorkspace: async function (userId, workspaceId) {\n    try {\n      const memories = await prisma.memories.findMany({\n        where: {\n          userId: this.validations.userId(userId),\n          workspaceId: this.validations.id(workspaceId),\n          scope: \"workspace\",\n        },","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/f92433b4ea0598492a1e6645ea22addbb4dd1287/server/models/memory.js#L22-L58","documentation":"Memory's content validator requires a string with at least one non-whitespace character: typeof must be 'string' and v.trim().length must exceed 0. Null, numbers, arrays, empty strings, and whitespace-only strings all fail before any database write.","triggerScenarios":"Passing content: '' or content: '   '; content built from empty template variables; sending numbers or nested objects where a text note is expected; undefined destructured from a payload.","commonSituations":"Memory-saving features fed by optional form fields that were left blank; LLM-generated memories that produced empty output; client sending JSON numbers for what the server treats as text.","solutions":["Trim and check for non-empty text before calling the memory API","Default optional inputs to a meaningful value or skip the call entirely","Ensure the client sends content as a JSON string, not a number or object"],"exampleFix":"// before\nMemory.create({ userId, workspaceId, content: extracted?.summary ?? '' }); // '' throws\n\n// after\nconst summary = extracted?.summary?.trim();\nif (summary) {\n  Memory.create({ userId, workspaceId, content: summary });\n}","handlingStrategy":"validation","validationCode":"function isNonEmptyContent(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}\n\nif (!isNonEmptyContent(content)) {\n  return res.status(400).json({ error: 'content must be a non-empty string' });\n}","typeGuard":"/** @param {unknown} v */\nfunction isNonEmptyText(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await Memory.create({ userId, workspaceId, content });\n} catch (err) {\n  if (err.message === 'Content must be a non-empty string') {\n    return res.status(400).json({ error: 'Memory content cannot be blank' });\n  }\n  throw err;\n}","preventionTips":["Trim client input and skip the memory call entirely when nothing remains","Send content as a JSON string; never a number, object, or null","When memories are machine-generated (e.g. from LLM output), guard against empty generations before saving"],"tags":["memory","validation","empty-input"],"backgroundTag":"empty-required-field","analyzedSha":"f92433b4ea0598492a1e6645ea22addbb4dd1287","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}