Preserve iterable ToolError content - #1837
Open
sylvesterkaczmarek wants to merge 1 commit into
Open
Conversation
Jeffchiucp
pushed a commit
to Jeffchiucp/anthropic-sdk-python
that referenced
this pull request
Aug 18, 2026
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
Preserve structured
ToolErrorcontent when callers provide a one-shot iterable such as a generator.BetaFunctionToolResultTypeexplicitly acceptsIterable[BetaContent].ToolError.__init__()currently iterates non-string content to build the exception message and then stores the same iterable onself.content. For generators, that consumes the iterable before the tool runner later readsexc.content, so the emittedtool_resultloses the structured error content.Fix
Materialize non-string
ToolErrorcontent once before rendering the exception message. The same reusable collection is then retained onself.contentfor the runner.String content remains unchanged.
Regression coverage
Adds focused tests verifying:
tool_error_content(), the same path used by the runners;ToolErrorbehavior is unchanged.The production change is three lines in Anthropic's hand-maintained tool helper.