Skip to content

Only decode JSON input buffer in Anthropic Claude streaming#497

Merged
thpierce merged 4 commits intomainfrom
bedrock-patch
Oct 21, 2025
Merged

Only decode JSON input buffer in Anthropic Claude streaming#497
thpierce merged 4 commits intomainfrom
bedrock-patch

Conversation

@thpierce
Copy link
Contributor

@thpierce thpierce commented Oct 17, 2025

_decode_tool_use was only used when _tool_json_input_buf was found, but we were decoding the entire _content_block after adding _tool_json_input_buf to it. The _content_block overall which could contain non-JSON elements (e.g. {}), causing failures. To fix this, we have removed _decode_tool_use helper function and inlined JSON decoding logic directly into content_block_stop handler in _process_anthropic_claude_chunk, where we only use it to decode _tool_json_input_buf before appending to _content_block.

Patch based on open-telemetry/opentelemetry-python-contrib#3875 with code copied directly from https://github.com/open-telemetry/opentelemetry-python-contrib/blob/v0.54b1/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/bedrock_utils.py#L289

Repeated testing in open-telemetry/opentelemetry-python-contrib#3875 to confirm this works

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants