Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/strands/event_loop/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ def handle_content_block_stop(state: dict[str, Any]) -> dict[str, Any]:
try:
current_tool_use["input"] = json.loads(current_tool_use["input"])
except ValueError:
logger.warning(
"Failed to parse tool input JSON for '%s': %s",
current_tool_use.get("name", "unknown"),
current_tool_use["input"][:200] if isinstance(current_tool_use.get("input"), str) else "",
)
current_tool_use["input"] = {}

tool_use_id = current_tool_use["toolUseId"]
Expand Down
19 changes: 19 additions & 0 deletions tests/strands/event_loop/test_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,25 @@ def test_handle_content_block_delta(event: ContentBlockDeltaEvent, event_type, s
"redactedContent": b"",
},
),
# Tool Use - Malformed input JSON
(
{
"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
(
{
Expand Down