{"record":{"id":"ec4a9d6d48043f2a","repo":"mastra-ai/mastra","slug":"could-not-generate-title-from-input-json-stringi","errorCode":null,"errorMessage":"Could not generate title from input ${JSON.stringify(message)}","messagePattern":"Could not generate title from input (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/agent/agent.ts","lineNumber":3658,"sourceCode":"    const observabilityContext = resolveObservabilityContext(rest);\n    // need to use text, not object output or it will error for models that don't support structured output (eg Deepseek R1)\n    const llm = await this.getLLM({ requestContext, model });\n    // Register Mastra on the LLM (if any) so the inner agentic loop has access\n    // for storage/observability. Idempotent.\n    if (this.#mastra) {\n      llm.__registerMastra(this.#mastra);\n    }\n\n    let userContent: string;\n\n    if (messages && messages.length > 0) {\n      // Multi-message path: format all messages with roles\n      userContent = this.formatMessagesForTitle(messages);\n    } else if (message) {\n      // Single message path (backward compat): normalize and format\n      const normMessage = new MessageList().add(message, 'user').get.all.aiV5.ui().at(-1);\n      if (!normMessage) {\n        throw new Error(`Could not generate title from input ${JSON.stringify(message)}`);\n      }\n      userContent = this.formatMessagesForTitle([normMessage]);\n    } else {\n      throw new Error('Either message or messages must be provided');\n    }\n\n    if (!userContent) {\n      return undefined;\n    }\n\n    // Resolve instructions using the dedicated method\n    const systemInstructions = await this.resolveTitleInstructions(requestContext, instructions);\n\n    let text = '';\n\n    if (isSupportedLanguageModel(llm.getModel())) {\n      const messageList = new MessageList()\n        .add(","sourceCodeStart":3640,"sourceCodeEnd":3676,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent/agent.ts#L3640-L3676","documentation":"The agent's internal title generation normalizes the provided `message` through MessageList and needs at least one user message to format a prompt for the title model. If the normalized message list is empty (no last message), it throws this plain Error with the JSON-serialized input. This is an input-shape problem, not a model failure.","triggerScenarios":"Calling the title-generation path (e.g. agent.generateTitle / memory title generation) with a `message` whose content normalizes to zero messages — an empty string, an empty array of parts, or a malformed message object with no usable content.","commonSituations":"Auto-generating memory thread titles from empty user input, passing a message object that was never populated, or piping a UI value (empty input box) directly into title generation.","solutions":["Check the input for emptiness before calling title generation and skip the call (or supply a placeholder) when there is no user content.","Pass a plain non-empty string instead of a pre-built message object if the shape is uncertain.","If generating titles from multiple messages, use the `messages` array path with at least one populated user message."],"exampleFix":"// before\nawait agent.generateTitle({ message: userInput }); // userInput may be ''\n// after\nif (userInput && userInput.trim()) {\n  await agent.generateTitle({ message: userInput });\n}","handlingStrategy":"validation","validationCode":"function hasTitleableContent(input: unknown): boolean {\n  if (typeof input === 'string') return input.trim().length > 0;\n  if (Array.isArray(input)) return input.length > 0;\n  if (input && typeof input === 'object') {\n    const parts = (input as any).content?.parts ?? (input as any).parts;\n    return Array.isArray(parts) ? parts.length > 0 : Object.keys(input as object).length > 0;\n  }\n  return false;\n}","typeGuard":"function isNonEmptyUserMessage(m: unknown): m is { role: 'user'; content: string } {\n  const msg = m as any;\n  return !!msg && msg.role === 'user' && (typeof msg.content === 'string' ? msg.content.trim().length > 0 : !!msg.content?.parts?.length);\n}","tryCatchPattern":"try {\n  await agent.generateTitle({ message });\n} catch (err) {\n  if ((err as Error).message.startsWith('Could not generate title from input')) {\n    return null; // nothing titleable — skip title generation gracefully\n  }\n  throw err;\n}","preventionTips":["Gate title generation on non-empty, trimmed user input.","Pass plain strings rather than hand-built message objects when unsure of the shape.","Treat title generation as best-effort: catch and fall back to a default thread title."],"tags":["agent","memory","title-generation","invalid-input"],"backgroundTag":"empty-input-message","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}