{"record":{"id":"abef3cf29f7ae9e0","repo":"mastra-ai/mastra","slug":"capture-guidance-is-limited-to-max-guidance-leng","errorCode":null,"errorMessage":"capture-guidance is limited to ${MAX_GUIDANCE_LENGTH} characters.","messagePattern":"capture-guidance is limited to (.+?) characters\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/memory/src/processors/observational-memory/subconscious/knowledge-write-tools.ts","lineNumber":245,"sourceCode":"          scope: scopeLevelSchema,\n          expectedVersion: { type: 'integer', minimum: 1 },\n        },\n        required: ['name', 'content'],\n        additionalProperties: false,\n      } satisfies JSONSchema7,\n      execute: async input => {\n        const value = input as {\n          name: string;\n          kind?: string;\n          content: string;\n          scope?: KnowledgeScopeLevel;\n          expectedVersion?: number;\n        };\n        const trimmedName = value.name.trim();\n        const reservedName = trimmedName.toLowerCase();\n        const name = reservedName === 'capture-guidance' ? reservedName : trimmedName;\n        if (reservedName === 'capture-guidance' && value.content.length > MAX_GUIDANCE_LENGTH) {\n          throw new Error(`capture-guidance is limited to ${MAX_GUIDANCE_LENGTH} characters.`);\n        }\n        const store = await getStore(memory);\n        const scope = resolveWriteScope(options, value.scope);\n        const resolvedNode = await store.resolveNode({ name, scope });\n        const existing =\n          resolvedNode && knowledgeScopeKey(resolvedNode.scope) === knowledgeScopeKey(scope) ? resolvedNode : null;\n        if (!existing) {\n          if (value.expectedVersion !== undefined)\n            throw new Error('expectedVersion is only valid for an existing node.');\n          return store.createNode({\n            name,\n            kind: value.kind ?? 'document',\n            content: value.content,\n            scope,\n            resolutionScope: options.scope,\n          });\n        }\n        if (value.expectedVersion === undefined) throw new Error('Updating node content requires expectedVersion.');","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/processors/observational-memory/subconscious/knowledge-write-tools.ts#L227-L263","documentation":"When creating/updating the special 'capture-guidance' node (name is case-insensitively reserved), the content length is capped at MAX_GUIDANCE_LENGTH (4000) characters. This node injects instructions into capture prompts, so unbounded content would bloat every capture. The error is thrown before any storage call when a capture-guidance write exceeds the cap.","triggerScenarios":"Calling the node upsert tool with name 'capture-guidance' (any casing, trimmed) and content longer than 4000 characters.","commonSituations":"Long operating instructions pasted wholesale into guidance; cumulative guidance growth without pruning; LLM generating verbose guidance text.","solutions":["Shorten the capture-guidance content to 4000 characters or fewer and retry","Split content into concise bullet rules and drop redundant guidance","Pre-check value.content.length before the call and truncate or reject oversized guidance in your own tooling"],"exampleFix":"// before\nawait tool.execute({ name: 'capture-guidance', content: longInstructions, scope: 'org' });\n// after\nconst content = longInstructions.length > 4000 ? longInstructions.slice(0, 4000) : longInstructions;\nawait tool.execute({ name: 'capture-guidance', content, scope: 'org' });","handlingStrategy":"validation","validationCode":"if (name.trim().toLowerCase() === 'capture-guidance' && content.length > 4000) {\n  content = content.slice(0, 4000);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await tool.execute({ name, content, scope });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('capture-guidance is limited')) {\n    await tool.execute({ name, content: content.slice(0, 4000), scope });\n  } else throw e;\n}","preventionTips":["Keep capture-guidance under 4000 characters by writing terse rules","Enforce the limit in whatever UI/code lets users edit guidance","Periodically prune stale guidance entries"],"tags":["validation","string-length","memory"],"backgroundTag":"input-length-limit-exceeded","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}