Mintplex-Labs/anything-llm · warning
Content must be a non-empty string
Error message
Content must be a non-empty string
What it means
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.
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
Example fix
// before
Memory.create({ userId, workspaceId, content: extracted?.summary ?? '' }); // '' throws
// after
const summary = extracted?.summary?.trim();
if (summary) {
Memory.create({ userId, workspaceId, content: summary });
} Defensive patterns
Strategy: validation
Validate before calling
function isNonEmptyContent(v) {
return typeof v === 'string' && v.trim().length > 0;
}
if (!isNonEmptyContent(content)) {
return res.status(400).json({ error: 'content must be a non-empty string' });
} Type guard
/** @param {unknown} v */
function isNonEmptyText(v) {
return typeof v === 'string' && v.trim().length > 0;
} Try / catch
try {
await Memory.create({ userId, workspaceId, content });
} catch (err) {
if (err.message === 'Content must be a non-empty string') {
return res.status(400).json({ error: 'Memory content cannot be blank' });
}
throw err;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Content must be a non-empty string
- Invalid scope
- addToWorkspaces must be a string of comma-separated…
- ApiPie chat: is not valid for chat completion!
- " " is not a valid URL. Check your settings for the Azure…
AI-assisted analysis of Mintplex-Labs/anything-llm@f92433b4ea (2026-08-18).
Data as JSON: /api/errors/963e86491dad1dc2.
Report an issue: GitHub.
Appendix: source
Thrown at server/models/memory.js:40
const Memory = {
GLOBAL_LIMIT: 5,
WORKSPACE_LIMIT: 20,
MAX_INJECTED_WORKSPACE_LIMIT: 5,
VALID_SCOPES: ["workspace", "global"],
validations: {
id: (v) => toInt(v),
userId: (v = null) => (v === null || v === undefined ? null : toInt(v)),
workspaceId: (v = null) =>
v === null || v === undefined ? null : toInt(v),
scope: (v = "workspace") => {
if (!Memory.VALID_SCOPES.includes(v))
throw new Error(`Invalid scope: ${JSON.stringify(v)}`);
return v;
},
content: (v) => {
if (typeof v !== "string" || v.trim().length === 0)
throw new Error("Content must be a non-empty string");
return v;
},
},
/**
* List a user's workspace-scoped memories, newest first.
* @param {number|null} userId
* @param {number} workspaceId
* @returns {Promise<Memory[]>}
*/
forUserWorkspace: async function (userId, workspaceId) {
try {
const memories = await prisma.memories.findMany({
where: {
userId: this.validations.userId(userId),
workspaceId: this.validations.id(workspaceId),
scope: "workspace",
},View on GitHub (pinned to f92433b4ea)