fix: remove empty Content block from tool-call-only messages#104
Open
zarusz wants to merge 1 commit intodevlooped:mainfrom
Open
fix: remove empty Content block from tool-call-only messages#104zarusz wants to merge 1 commit intodevlooped:mainfrom
zarusz wants to merge 1 commit intodevlooped:mainfrom
Conversation
The xAI gRPC API previously required at least one Content entry per message, including assistant messages that only carry tool calls (no text). A workaround padded those messages with an empty `new Content()` to satisfy that constraint. The API has since reversed this requirement and now rejects any message that contains an empty content block with: Status(StatusCode="InvalidArgument", Detail="Empty content block") Remove the padding. Messages with tool calls and no text content are now sent with an empty Content collection, which the API accepts. Signed-off-by: Tomasz Maruszak <maruszaktomasz@gmail.com>
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.
Fix: Empty content block error on tool-call messages
Root cause
MapToRequestcontained a workaround (added when the API was firstintegrated) that padded any assistant message containing tool calls but
no text content with a synthetic empty
Contentblock:The xAI gRPC API has since changed its validation: it now rejects
messages that contain an empty content block, returning:
This surfaces whenever the model performs a function/tool call, because
the subsequent round-trip includes an assistant message whose
Contentscontains only
FunctionCallContentitems and no text.Fix
Remove the padding block entirely. Assistant messages with only tool
calls are sent with an empty
Contentcollection, which the API nowaccepts without error.
Test
GrokDoesNotAddEmptyContentToToolCallOnlyMessages— a unit test (noAPI key required) that drives a conversation containing a tool-call-only
assistant turn through
MapToRequestvia a mockedChatClientandasserts that no message in the outgoing request contains a zero-size
Contententry.