fix(xai, deepseek, groq, mistral): send null content for tool-only assistant messages#14987
Closed
Mmartinrusso wants to merge 3 commits into
Closed
fix(xai, deepseek, groq, mistral): send null content for tool-only assistant messages#14987Mmartinrusso wants to merge 3 commits into
Mmartinrusso wants to merge 3 commits into
Conversation
…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>
978dd91 to
ac6774e
Compare
4 tasks
…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>
Collaborator
|
marking as closed - see #14612 (comment) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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