Skip to content

fix: add warning log when tool input JSON parsing fails#2064

Open
Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Zelys-DFKH:fix/streaming-tool-json-parse-warning
Open

fix: add warning log when tool input JSON parsing fails#2064
Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Zelys-DFKH:fix/streaming-tool-json-parse-warning

Conversation

@Zelys-DFKH
Copy link
Copy Markdown

Description

When a model returns tool input that cannot be parsed as JSON, the SDK silently falls back to an empty dict. This makes it impossible to distinguish between a tool that legitimately received {} from the model and one that received unparseable content.

This change adds a WARNING log before the fallback that includes the tool name and the first 200 characters of the raw input, making the silent failure observable in logs.

Related Issues

Fixes #2051

Documentation PR

N/A

Type of Change

Bug fix

Testing

Added test_handle_content_block_stop_invalid_json_logs_warning to tests/strands/event_loop/test_streaming.py. The test verifies that when handle_content_block_stop encounters invalid JSON tool input, it falls back to {} and emits a warning log containing "failed to parse tool input as JSON".

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

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

When a model returns malformed tool input that cannot be parsed as
JSON, the SDK silently falls back to an empty dict. This adds a
warning log with the tool name and the first 200 characters of the
raw input to aid debugging.

Fixes strands-agents#2051
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Malformed tool input JSON silently replaced with empty dict, no logging

1 participant