sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[BUG] Streamed tool input that is valid JSON but not an object (e.g. null) is passed to the tool as-is

Open goranai opened this issue 3 weeks ago • 1 comments

Human Overview

If the model sends null as the tool input, it errors right away. It should just be treated as empty.

Checks

  • [x] I have updated to the lastest minor and patch version of Strands
  • [x] I have checked the documentation and this is not expected behavior
  • [x] I have searched ./issues and there are no duplicates of my issue

SDK Language

Python

Strands Version

main @ 75a0cdd (editable install from source)

Language Runtime Version

Python 3.13.15

Operating System

Windows 11

Installation Method

git clone

Steps to Reproduce

Use a model whose stream emits a toolUse whose input is null for a zero-argument tool. I have not tested a live provider. A pipecat issue (https://github.com/pipecat-ai/pipecat/issues/4059) reports a provider sending null tool arguments, so this may happen in practice. The script below uses the repo's own test fixture, tests/fixtures/mocked_model_provider.py, which json.dumps None to "null":

from mocked_model_provider import MockedModelProvider  # copied from tests/fixtures
from strands import Agent, tool

@tool
def ping() -> str:
    """Return ok."""
    return "ok"

model = MockedModelProvider([
    {"role": "assistant", "content": [{"toolUse": {"toolUseId": "t1", "name": "ping", "input": None}}]},
    {"role": "assistant", "content": [{"text": "done"}]},
])
agent = Agent(model=model, tools=[ping], callback_handler=None)
agent("go")
for m in agent.messages:
    for c in m["content"]:
        if "toolUse" in c: print("toolUse input:", repr(c["toolUse"]["input"]))
        if "toolResult" in c: print("toolResult:", c["toolResult"]["status"], c["toolResult"]["content"])

Expected Behavior

The tool runs with {}, the same as empty input (#4195) or unparseable input (#2054). ToolUse.input is typed as a dict.

Actual Behavior

toolUse input: None
toolResult: error [{'text': 'Error: Validation failed for input parameters: strands.tools.decorator.PingTool() argument after ** must be a mapping, not NoneType'}]

handle_content_block_stop (strands-py/src/strands/event_loop/streaming.py) stores whatever json.loads(raw_input) returns, so [1], 5, "x", true and NaN also become the tool input. The assistant message in history keeps that non-dict input too.

Possible Solution

In handle_content_block_stop, treat a parsed value that is not a dict like unparseable input: {} plus the existing warning. That is 3 lines and a parametrized test, and I can open a PR if you want one. If #4655 lands first, the same check could route non-object input to its error tool result instead. Either is fine with me.

Additional Context

  • Not tested: whether a provider rejects the resent non-dict input in history (needs a live API).
  • The TypeScript SDK looks the same from a read of strands-ts/src/models/model.ts:629 (JSON.parse(accumulatedToolInput) with no object check), but I did not run it.
  • The experimental bidi models (openai/realtime.py:681, openai/live.py:689, bedrock.py:871) also use json.loads(...) as tool input unchecked. I read these only and did not run them.
  • Tested with the fix: pytest -n 2 tests/strands/event_loop tests/strands/tools 938 passed, 31 skipped (the 5 new cases fail without it); ruff check, ruff format --check and mypy on streaming.py clean. Not run: hatch run prepare, full mypy, CI.

AI disclosure: the details above were drafted with AI assistance (Claude Opus 5.5); the Human Overview is my own words, translated from Indonesian.

Related Issues

#2051, #4655

goranai avatar Nov 10 '26 17:11 goranai

Thanks @goranai for filing the issue. Without an E2E example that's confirmed, we cannot accept this as a bug report.

If this is more than a hypothetical scenario, you can open a new issue with traces.

opieter-aws avatar Nov 12 '26 22:11 opieter-aws