Skip to content

Bug: tool-only assistant messages send content:"" in xai, deepseek, groq, mistral providers #14612

@gr2m

Description

@gr2m

Summary

Follow-up to #13466 / #13744.

The same pattern that caused Bedrock ValidationException: messages: text content blocks must be non-empty in @ai-sdk/openai-compatible and @ai-sdk/openai also exists in four other provider packages. When an assistant message contains only tool-call parts (no text), the converter emits content: "", which Bedrock-backed endpoints reject.

Affected files

  • packages/xai/src/convert-to-xai-chat-messages.ts:111
  • packages/deepseek/src/chat/convert-to-deepseek-chat-messages.ts:126
  • packages/groq/src/convert-to-groq-chat-messages.ts:105
  • packages/mistral/src/convert-to-mistral-chat-messages.ts:122

Each has the same shape:

messages.push({
  role: 'assistant',
  content: text, // <-- empty string when only tool-calls are present
  tool_calls: toolCalls.length > 0 ? toolCalls : undefined,
});

Proposed fix

Apply the same change as #13744:

content: text || null,

This matches the OpenAI spec (content is nullable when tool_calls is present) and what official OpenAI SDKs send.

Scope

  • Update each converter.
  • Update corresponding unit tests to expect null for tool-only assistant messages.
  • Add a patch changeset covering the four packages.

Note: Mistral uses its own API shape; verify Mistral's spec accepts null before applying there. The other three (xai, deepseek, groq) are OpenAI-compatible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai/providerrelated to a provider package. Must be assigned together with at least one `provider/*` labelbugSomething isn't working as documentedprovider/deepseekIssues related to the @ai-sdk/deepseek providerprovider/groqIssues related to the @ai-sdk/groq providerprovider/mistralIssues related to the @ai-sdk/mistral providerprovider/xaiIssues related to the @ai-sdk/xai providerreproduction provided

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions