Mintplex-Labs/anything-llm · warning · Error

Content must be a non-empty string

Error message

Content must be a non-empty string

What it means

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.

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 526360e320)

Solutions

  1. Ensure content is a non-empty trimmed string before calling the model.
  2. Guard at the API boundary: reject empty content with a 400 instead of reaching the model.
  3. If memory extraction can legitimately be empty, skip the create call entirely.
  4. Coerce and validate: String(content).trim(); abort if length === 0.

Example fix

// before
await Memory.create({ userId, content: extractedText });
// after
const content = String(extractedText ?? '').trim();
if (!content) return { skipped: true };
await Memory.create({ userId, content });
Defensive patterns

Strategy: validation

Validate before calling

const content = typeof input.content === 'string' ? input.content.trim() : '';
if (content.length === 0) return { skipped: true, reason: 'empty content' };

Type guard

function isNonEmptyString(v) {
  return typeof v === 'string' && v.trim().length > 0;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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