fix(models): add tool_reference content block support#90
Open
bhaskoro-muthohar wants to merge 2 commits intojwadow:mainfrom
Open
fix(models): add tool_reference content block support#90bhaskoro-muthohar wants to merge 2 commits intojwadow:mainfrom
bhaskoro-muthohar wants to merge 2 commits intojwadow:mainfrom
Conversation
|
Have tried this code out and it works, seems to avoid the issues with tool calling. Thanks! |
… deferred tools Claude Code v2.1.69+ sends tool_reference blocks inside tool_result messages when using the ToolSearch deferred tool mechanism. Without this fix, the gateway rejects these blocks with Pydantic validation errors.
…ly route changes - Add tests for ToolReferenceContentBlock model validation - Add test for ToolResultContentBlock accepting tool_reference in content - Add test for ContentBlock union accepting tool_reference - Add test for extract_text_content skipping tool_reference blocks - Revert whitespace-only changes in routes_anthropic.py and routes_openai.py
ba2eaeb to
0708463
Compare
juslintek
added a commit
to juslintek/kiro-gateway
that referenced
this pull request
Mar 21, 2026
…ol_result content blocks Claude Code v2.1.69+ sends tool_reference blocks inside tool_result content when using the deferred tool search feature (ENABLE_TOOL_SEARCH=true). The Anthropic API also returns server_tool_use and tool_search_tool_result blocks for server-side tool search invocations. Without these models, Pydantic validation rejects requests containing these block types with 422 errors. Changes: - Add ToolReferenceContentBlock model (type='tool_reference') - Add ServerToolUseContentBlock model (type='server_tool_use') - Add ToolSearchResultContentBlock model (type='tool_search_tool_result') - Add ToolReferenceContentBlock to ToolResultContentBlock.content union - Add all three to ContentBlock union - Add model_config extra=allow to ToolResultContentBlock for cache_control Related: jwadow#90, jwadow#96, jwadow#82 (different approaches to the same 422 issue)
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.
Summary
ToolReferenceContentBlockmodel for Claude Code v2.1.69+ deferred tools (ToolSearch)ToolResultContentBlock.contentunion andContentBlockuniontool_referenceinextract_text_content()to avoid polluting text extractionextra = "allow"onToolResultContentBlockfor forward compatibilityFixes #89
Test plan
ToolReferenceContentBlockmodel validationextract_text_contentskippingtool_referenceblocks