Fix ToolResultBlockParam to support both string and array content#297
Open
joaquinhuigomez wants to merge 1 commit intoanthropics:mainfrom
Open
Fix ToolResultBlockParam to support both string and array content#297joaquinhuigomez wants to merge 1 commit intoanthropics:mainfrom
joaquinhuigomez wants to merge 1 commit intoanthropics:mainfrom
Conversation
…mats The API docs state that tool_result content can be either a string (e.g. "content": "15 degrees") or an array of content blocks. The SDK previously only supported the array format, causing deserialization errors when content was a plain string. Changes: - Add ContentString field to ToolResultBlockParam and BetaToolResultBlockParam for explicit string content serialization - Update MarshalJSON to output content as a string when ContentString is set - Update UnmarshalJSON to handle string content by normalizing it into a Content array with a single TextBlock - Update NewToolResultBlock to use string format (matches API docs examples) - Add NewToolResultBlockFromArray for explicit array content construction - Add NewBetaToolResultStringBlockParam for explicit string content - Add comprehensive tests for both formats Fixes anthropics#182
edefef9 to
c907622
Compare
Author
|
Hi — just checking if this is still on the review queue. Happy to address any feedback. |
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.
The Anthropic API accepts tool results as either a plain string or an array of content blocks, but the Go SDK's ToolResultBlockParam only serializes the array form. This adds support for both formats with a ContentString field and custom JSON marshaling that picks the right wire format automatically.