{"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":"Error","httpStatus":null,"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/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/models/memory.js#L22-L58","documentation":"Thrown by the Memory model's content validator. Content must be a string and must have non-zero length after trim. This rejects null, undefined, numbers, objects, empty strings, and whitespace-only strings before they reach the database.","triggerScenarios":"Calling Memory.create/update with content that is undefined, null, a number, an empty string, or only whitespace. Often the result of reading a form/request field that was never populated.","commonSituations":"The agent/LLM produced an empty memory extraction; the request body omitted the content field; a .trim() chain on undefined threw earlier and a default empty string slipped through; JSON deserialization yielded a non-string.","solutions":["Ensure content is a non-empty trimmed string before calling the model.","Guard at the API boundary: reject empty content with a 400 instead of reaching the model.","If memory extraction can legitimately be empty, skip the create call entirely.","Coerce and validate: String(content).trim(); abort if length === 0."],"exampleFix":"// before\nawait Memory.create({ userId, content: extractedText });\n// after\nconst content = String(extractedText ?? '').trim();\nif (!content) return { skipped: true };\nawait Memory.create({ userId, content });","handlingStrategy":"validation","validationCode":"const content = typeof input.content === 'string' ? input.content.trim() : '';\nif (content.length === 0) return { skipped: true, reason: 'empty content' };","typeGuard":"function isNonEmptyString(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":null,"preventionTips":["Reject empty content at the API boundary with a 400.","Skip memory creation when extraction yields nothing rather than passing ''.","Always trim and length-check before persisting."],"tags":["memory","validation","input-validation","string"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}