Skip to content

opentelemetry-instrumentation-botocore fails to parse tool use input #3843

@bhardwaj-vipul

Description

@bhardwaj-vipul

Describe your environment

Python version: (Python 3.11)
opentelemetry-instrumentation-botocore==0.54b1
aws-opentelemetry-distro>=0.10.0

What happened?

Getting Type Error JSON object must be str, bytes or bytearray, not dict
while parsing tool use input in _decode_tool_use

Steps to Reproduce

Tool Use Input is of dict type here.

Expected Result

Tool input should be parsed successfully.

Actual Result

  File "/app/.venv/lib/python3.11/site-packages/langchain_aws/chat_models/bedrock.py", line 871, in _stream
    for chunk in self._prepare_input_and_invoke_stream(
  File "/app/.venv/lib/python3.11/site-packages/langchain_aws/llms/bedrock.py", line 1129, in _prepare_input_and_invoke_stream
    for chunk in LLMInputOutputAdapter.prepare_output_stream(
  File "/app/.venv/lib/python3.11/site-packages/langchain_aws/llms/bedrock.py", line 503, in prepare_output_stream
    for event in stream:
  File "/app/.venv/lib/python3.11/site-packages/opentelemetry/instrumentation/botocore/extensions/bedrock_utils.py", line 170, in __iter__
    self._process_event(event)
  File "/app/.venv/lib/python3.11/site-packages/opentelemetry/instrumentation/botocore/extensions/bedrock_utils.py", line 192, in _process_event
    self._process_anthropic_claude_chunk(chunk)
  File "/app/.venv/lib/python3.11/site-packages/opentelemetry/instrumentation/botocore/extensions/bedrock_utils.py", line 332, in _process_anthropic_claude_chunk
    _decode_tool_use(self._content_block)
  File "/app/.venv/lib/python3.11/site-packages/opentelemetry/instrumentation/botocore/extensions/bedrock_utils.py", line 42, in _decode_tool_use
    tool_use["input"] = json.loads(tool_use["input"])
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/__init__.py", line 339, in loads
    raise TypeError(f'the JSON object must be str, bytes or bytearray,

Additional context

This issue is happening specifically when there are no arguments in the tool calls. Because when tool call has no argument then this block of code is hit and we get the error. If there are tool arguments, then a partial_json is sent and we do not hit this error. This is an edge case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions