-
Notifications
You must be signed in to change notification settings - Fork 828
fix(streaming): log warning when tool input JSON is malformed #2054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -366,6 +366,25 @@ def test_handle_content_block_delta(event: ContentBlockDeltaEvent, event_type, s | |
| "redactedContent": b"", | ||
| }, | ||
| ), | ||
| # Tool Use - Malformed input JSON | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue: The new parametrized test case verifies the state transformation (malformed JSON → Suggestion: Add a dedicated test that uses @unittest.mock.patch("strands.event_loop.streaming.logger")
def test_handle_content_block_stop_logs_warning_on_malformed_json(mock_logger):
state = {
"content": [],
"current_tool_use": {"toolUseId": "123", "name": "test_tool", "input": "{invalid json}"},
"text": "",
"reasoningText": "",
"citationsContent": [],
"redactedContent": b"",
}
strands.event_loop.streaming.handle_content_block_stop(state)
mock_logger.warning.assert_called_once()
call_args = mock_logger.warning.call_args
assert "test_tool" in str(call_args)
assert "{invalid json}" in str(call_args) |
||
| ( | ||
| { | ||
| "content": [], | ||
| "current_tool_use": {"toolUseId": "123", "name": "test", "input": "{invalid json}"}, | ||
| "text": "", | ||
| "reasoningText": "", | ||
| "citationsContent": [], | ||
| "redactedContent": b"", | ||
| }, | ||
| { | ||
| "content": [{"toolUse": {"toolUseId": "123", "name": "test", "input": {}}}], | ||
| "current_tool_use": {}, | ||
| "text": "", | ||
| "reasoningText": "", | ||
| "citationsContent": [], | ||
| "redactedContent": b"", | ||
| }, | ||
| ), | ||
| # Text | ||
| ( | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue: The log message doesn't follow the project's structured logging format defined in AGENTS.md.
The format requires
field=<value>pairs separated by commas, followed by a pipe|and a lowercase human-readable message. Compare with the existing warning on line 349 in this same file:Suggestion: