Skip to content

Message Validation Error in Chat Stream: messages.2: all messages must have non-empty content except for the optional final assistant message #11776

@AsafBenjaminov

Description

@AsafBenjaminov

Description

Bug Report: Message Validation Error After Tool Approval

Error Message

Error: messages.2: all messages must have non-empty content except for the optional final assistant message

When It Occurs

This error occurs only after approving tool calls. The flow is:

  1. User sends an approval via addToolApprovalResponse()
  2. sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses triggers auto-send
  3. Error is thrown during the streaming response

Environment

Backend:

  • ai: v6.0.33
  • @ai-sdk/anthropic: v3.0.0-beta.98

Frontend:

  • @ai-sdk/react: v3.0.35

Code Location

Backend - Where error is caught

// chat.service.ts line 1221
const result = createAgentUIStreamResponse({
    agent: agentRunner,
    uiMessages: processedMessages,
    generateMessageId,
    onError: (error) => {
        // Error appears here after tool approval
        console.error("Failed to stream chat:", error);
        return error.message;
    },
});

Frontend - Auto-send configuration

// use-chat-wrapper.ts line 131
const { addToolApprovalResponse } = useChat({
    transport: transport as any as ChatTransport<any>,
    sendAutomaticallyWhen: (options) =>
        lastAssistantMessageIsCompleteWithApprovalResponses(options) ||
        lastAssistantMessageIsCompleteWithToolCalls(options),
});

Frontend - Sending approval

// use-chat-wrapper.ts line 263
const sendToolApprovalResponse = async (approvalId: string, approved: boolean) => {
    await addToolApprovalResponse({
        id: approvalId,
        approved,
    });
    // sendAutomaticallyWhen triggers here and error occurs during streaming
};

Observations

  1. Error only occurs after tool approval, not during initial tool call
  2. Our messages use parts-based format without top-level content field
  3. Error is caught in onError callback of createAgentUIStreamResponse
  4. Error happens only after calling tools that are marked needsApproval and granting them the approval

Questions

  1. Does createAgentUIStreamResponse require a content field on messages after tool approval responses?
  2. Should approval response messages automatically generate a content field?

AI SDK Version

  • ai: 6.0.33
  • @ai-sdk/react: 3.0.35

Same error occured on these versions

  • ai: 6.0.0-beta.169
  • @AI-SDK: 3.0.0-beta.172

Tried to update but did not resolve.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions