Skip to content

fix(models): add tool_reference content block support#90

Open
bhaskoro-muthohar wants to merge 2 commits intojwadow:mainfrom
bhaskoro-muthohar:fix/tool-reference-content-block
Open

fix(models): add tool_reference content block support#90
bhaskoro-muthohar wants to merge 2 commits intojwadow:mainfrom
bhaskoro-muthohar:fix/tool-reference-content-block

Conversation

@bhaskoro-muthohar
Copy link
Copy Markdown

@bhaskoro-muthohar bhaskoro-muthohar commented Mar 5, 2026

Summary

  • Add ToolReferenceContentBlock model for Claude Code v2.1.69+ deferred tools (ToolSearch)
  • Include it in ToolResultContentBlock.content union and ContentBlock union
  • Skip tool_reference in extract_text_content() to avoid polluting text extraction
  • Add extra = "allow" on ToolResultContentBlock for forward compatibility

Fixes #89

Test plan

  • Existing tests pass (327 passed)
  • Add unit tests for ToolReferenceContentBlock model validation
  • Add unit tests for extract_text_content skipping tool_reference blocks
  • Test with Claude Code session using deferred tools (ToolSearch)
image

@fn5
Copy link
Copy Markdown

fn5 commented Mar 7, 2026

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
@bhaskoro-muthohar bhaskoro-muthohar force-pushed the fix/tool-reference-content-block branch from ba2eaeb to 0708463 Compare March 15, 2026 04:11
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed Contributor License Agreement has been signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: support tool_reference content blocks from Claude Code deferred tools

2 participants