Repository navigation
fix(litellm): record every tool_result block of an anthropic message, not just the last - #3818
Merged
caroger merged 4 commits intoSep 30, 2026
Conversation
… not just the last
This was referenced Sep 23, 2026
ialisaleh
reviewed
Sep 30, 2026
ialisaleh
left a comment
Collaborator
There was a problem hiding this comment.
I reviewed the PR, and the change fixes the reported case by recording each parallel string tool result as a separate tool message with its content and tool_call_id. The regression test covers both results. As a follow-up, we can check list-valued tool_result.content, since the new path changes how it is recorded and may omit some nested block types. Thanks!
caroger
approved these changes
Sep 30, 2026
Merged
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.
Fixes #3817
When a user message carries several
tool_resultblocks (the standard reply to parallel tool calls), litellm's anthropic messages extractor writes every block to the same two keys,message.contentandmessage.tool_call_id, at the message's index. Only the last block reaches the span; the earlier tool results are dropped from the trace.This change records each
tool_resultblock as its own input message withmessage.role = "tool",message.content, andmessage.tool_call_id:tool_resultblocks expands into one tool message per block instead of a single "user" message that keeps only the last result.Same fix shape as #3810 (anthropic), #3812 (vertexai), and #3814 (google-genai), per spec/tool_calling.md.
Test plan:
test_create_input_multiple_tool_result_blocksin tests/test_anthropic_messages.py; fails on main and passes with this change.pytest tests/test_anthropic_messages.py- 24 passed, including the existing content-block tests, which are unaffected.