fix(openai, openai-compatible): send null content for tool-only assistant messages#13744
Merged
Conversation
ghost
pushed a commit
that referenced
this pull request
Apr 17, 2026
…tant messages (#13744) ## background when an assistant message contains only tool-call parts (no text), `convertToOpenAICompatibleChatMessages` and `convertToOpenAIChatMessages` send `content: ""`. providers backed by AWS Bedrock reject this with `ValidationException: messages: text content blocks must be non-empty` ## summary - change `content: text` to `content: text || null` for assistant messages in both `@ai-sdk/openai-compatible` and `@ai-sdk/openai` - update tests to expect `null` instead of `""` for tool-only assistant messages ## checklist - [x] tests have been added / updated (for bug fixes / features) - [ ] documentation has been added / updated (for bug fixes / features) - [x] a _patch_ changeset for relevant packages has been added (run `pnpm changeset` in root) - [x] i have reviewed this pull request (self-review) ## Future work The same `content: text` pattern exists in `@ai-sdk/xai`, `@ai-sdk/deepseek`, `@ai-sdk/groq`, and `@ai-sdk/mistral` and will hit the same Bedrock error under equivalent routing. Tracked separately in #14612. ## related issues fixes #13466
|
✅ Backport PR created: #14613 |
aayush-kapoor
added a commit
that referenced
this pull request
Apr 17, 2026
## Background CI was breaking ( a test wasn't updated for some reason ) after this PR #13744 ## Summary updated snapshot
mvtandas
added a commit
to mvtandas/ai
that referenced
this pull request
Apr 17, 2026
…sistant messages When an assistant message contains only tool-call parts (no text), the converters send content: "". Providers backed by AWS Bedrock reject this with: ValidationException: messages: text content blocks must be non-empty. This applies the same fix from vercel#13744 (openai, openai-compatible) to the remaining four providers: xai, deepseek, groq, and mistral. Change: content: text → content: text || null Fixes vercel#14612
|
🚀 Published in:
|
3 tasks
|
This breaks vanilla openai with "Invalid value for 'content': expected a string, got null" if you happen to have no tool calls and empty text. cc @dancer |
Collaborator
Author
|
@relayking ty for letting me know i'll take a look today |
dancer
added a commit
that referenced
this pull request
May 4, 2026
dancer
added a commit
that referenced
this pull request
May 4, 2026
…messages with tool calls (#14950) ## background #13744 changed `content: text` to `content: text || null` for assistant messages. this correctly fixed tool-only messages (openai requires `content: null` when `tool_calls` is present), but also broke the case where an assistant message has empty text and no tool calls - openai rejects `content: null` when `tool_calls` is absent with "Invalid value for 'content': expected a string, got null" per the [openai api spec](https://developers.openai.com/api/reference/go/resources/chat/subresources/completions), content is "required unless `tool_calls` or `function_call` is specified" ## summary - only send `null` when `toolCalls.length > 0`, otherwise preserve the text string - add regression tests for both `@ai-sdk/openai` and `@ai-sdk/openai-compatible` ## verification verified against live openai chat completions api with `openai.chat('gpt-4o-mini')` - empty assistant content now sends `content: ""` and returns a valid response ## related issues follow-up to #13744
Mmartinrusso
added a commit
to Mmartinrusso/ai
that referenced
this pull request
May 5, 2026
…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>
Mmartinrusso
added a commit
to Mmartinrusso/ai
that referenced
this pull request
May 5, 2026
…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>
4 tasks
This was referenced May 18, 2026
gr2m
pushed a commit
that referenced
this pull request
Jun 5, 2026
…tant messages (#13744) ## background when an assistant message contains only tool-call parts (no text), `convertToOpenAICompatibleChatMessages` and `convertToOpenAIChatMessages` send `content: ""`. providers backed by AWS Bedrock reject this with `ValidationException: messages: text content blocks must be non-empty` ## summary - change `content: text` to `content: text || null` for assistant messages in both `@ai-sdk/openai-compatible` and `@ai-sdk/openai` - update tests to expect `null` instead of `""` for tool-only assistant messages ## checklist - [x] tests have been added / updated (for bug fixes / features) - [ ] documentation has been added / updated (for bug fixes / features) - [x] a _patch_ changeset for relevant packages has been added (run `pnpm changeset` in root) - [x] i have reviewed this pull request (self-review) ## Future work The same `content: text` pattern exists in `@ai-sdk/xai`, `@ai-sdk/deepseek`, `@ai-sdk/groq`, and `@ai-sdk/mistral` and will hit the same Bedrock error under equivalent routing. Tracked separately in #14612. ## related issues fixes #13466
gr2m
pushed a commit
that referenced
this pull request
Jun 5, 2026
## Background CI was breaking ( a test wasn't updated for some reason ) after this PR #13744 ## Summary updated snapshot
gr2m
pushed a commit
that referenced
this pull request
Jun 5, 2026
…messages with tool calls (#14950) ## background #13744 changed `content: text` to `content: text || null` for assistant messages. this correctly fixed tool-only messages (openai requires `content: null` when `tool_calls` is present), but also broke the case where an assistant message has empty text and no tool calls - openai rejects `content: null` when `tool_calls` is absent with "Invalid value for 'content': expected a string, got null" per the [openai api spec](https://developers.openai.com/api/reference/go/resources/chat/subresources/completions), content is "required unless `tool_calls` or `function_call` is specified" ## summary - only send `null` when `toolCalls.length > 0`, otherwise preserve the text string - add regression tests for both `@ai-sdk/openai` and `@ai-sdk/openai-compatible` ## verification verified against live openai chat completions api with `openai.chat('gpt-4o-mini')` - empty assistant content now sends `content: ""` and returns a valid response ## related issues follow-up to #13744
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
when an assistant message contains only tool-call parts (no text),
convertToOpenAICompatibleChatMessagesandconvertToOpenAIChatMessagessendcontent: "". providers backed by AWS Bedrock reject this withValidationException: messages: text content blocks must be non-emptysummary
content: texttocontent: text || nullfor assistant messages in both@ai-sdk/openai-compatibleand@ai-sdk/openainullinstead of""for tool-only assistant messageschecklist
pnpm changesetin root)related issues
fixes #13466
Future work
The same
content: textpattern exists in@ai-sdk/xai,@ai-sdk/deepseek,@ai-sdk/groq, and@ai-sdk/mistraland will hit the same Bedrock error under equivalent routing. Tracked separately in #14612.