mastra-ai/mastra · error · Error
Could not generate title from input ${JSON.stringify(message
Error message
Could not generate title from input ${JSON.stringify(message)} What it means
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.
Source
Thrown at packages/core/src/agent/agent.ts:3658
const observabilityContext = resolveObservabilityContext(rest);
// need to use text, not object output or it will error for models that don't support structured output (eg Deepseek R1)
const llm = await this.getLLM({ requestContext, model });
// Register Mastra on the LLM (if any) so the inner agentic loop has access
// for storage/observability. Idempotent.
if (this.#mastra) {
llm.__registerMastra(this.#mastra);
}
let userContent: string;
if (messages && messages.length > 0) {
// Multi-message path: format all messages with roles
userContent = this.formatMessagesForTitle(messages);
} else if (message) {
// Single message path (backward compat): normalize and format
const normMessage = new MessageList().add(message, 'user').get.all.aiV5.ui().at(-1);
if (!normMessage) {
throw new Error(`Could not generate title from input ${JSON.stringify(message)}`);
}
userContent = this.formatMessagesForTitle([normMessage]);
} else {
throw new Error('Either message or messages must be provided');
}
if (!userContent) {
return undefined;
}
// Resolve instructions using the dedicated method
const systemInstructions = await this.resolveTitleInstructions(requestContext, instructions);
let text = '';
if (isSupportedLanguageModel(llm.getModel())) {
const messageList = new MessageList()
.add(View on GitHub (pinned to 75dd419e61)
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.
Example fix
// before
await agent.generateTitle({ message: userInput }); // userInput may be ''
// after
if (userInput && userInput.trim()) {
await agent.generateTitle({ message: userInput });
} Defensive patterns
Strategy: validation
Validate before calling
function hasTitleableContent(input: unknown): boolean {
if (typeof input === 'string') return input.trim().length > 0;
if (Array.isArray(input)) return input.length > 0;
if (input && typeof input === 'object') {
const parts = (input as any).content?.parts ?? (input as any).parts;
return Array.isArray(parts) ? parts.length > 0 : Object.keys(input as object).length > 0;
}
return false;
} Type guard
function isNonEmptyUserMessage(m: unknown): m is { role: 'user'; content: string } {
const msg = m as any;
return !!msg && msg.role === 'user' && (typeof msg.content === 'string' ? msg.content.trim().length > 0 : !!msg.content?.parts?.length);
} Try / catch
try {
await agent.generateTitle({ message });
} catch (err) {
if ((err as Error).message.startsWith('Could not generate title from input')) {
return null; // nothing titleable — skip title generation gracefully
}
throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Either message or messages must be provided
- Received input message with wrong threadId. Input ${message.
- Received input message with wrong resourceId. Input ${messag
- Found unhandled message ${JSON.stringify(message)}
- resourceId and threadId are required to queue a message
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/ec4a9d6d48043f2a.
Report an issue: GitHub.