Skip to content

fix(xai, deepseek, groq, mistral): send null content for tool-only assistant messages#14987

Closed
Mmartinrusso wants to merge 3 commits into
vercel:mainfrom
Mmartinrusso:fix/tool-only-assistant-content-null
Closed

fix(xai, deepseek, groq, mistral): send null content for tool-only assistant messages#14987
Mmartinrusso wants to merge 3 commits into
vercel:mainfrom
Mmartinrusso:fix/tool-only-assistant-content-null

Conversation

@Mmartinrusso
Copy link
Copy Markdown
Contributor

@Mmartinrusso Mmartinrusso commented May 5, 2026

Background

xAI, DeepSeek, Groq, and Mistral strictly validate the `content` field on assistant messages. When an assistant turn contains only tool calls (no text), their message converters were setting `content: ''` (empty string). Several of these APIs reject an empty string and expect `null` or the field to be omitted.

Summary

In each converter, set `content: null` when there are tool calls and no text content, matching the behavior of the OpenAI converter and the expectations of these providers.

Manual Verification

Verified by inspecting serialized messages in unit tests: tool-only assistant turns now carry `content: null`.

Checklist

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root)
  • I have reviewed this pull request (self-review)

Mmartinrusso and others added 2 commits May 5, 2026 10:33
…sistant messages

Follow-up to vercel#13744 / PR vercel#13744 which fixed the same pattern in
@ai-sdk/openai and @ai-sdk/openai-compatible.

When an assistant message contains only tool-call parts (no text), these
four providers were sending content: "" — an empty string. Providers
backed by Amazon Bedrock reject this with:
  ValidationException: messages: text content blocks must be non-empty

Change: content: toolCalls.length > 0 ? text || null : text

This matches the OpenAI spec (content is nullable when tool_calls is
present) and what the official OpenAI SDKs send. Updated tests for all
four packages to expect null instead of "" for tool-only assistant turns.

Fixes vercel#14612

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tions

XaiAssistantMessage.content and MistralAssistantMessage.content now accept
`string | null` to match the runtime behavior where tool-only turns send
null instead of empty string. Groq and DeepSeek already had this in their types.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@aayush-kapoor
Copy link
Copy Markdown
Collaborator

marking as closed - see #14612 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants