Skip to content

fix(tools): don't coerce a non-object tool input in the session runner - #2048

Open
Lushiyao5 wants to merge 1 commit into
anthropics:mainfrom
Lushiyao5:contrib/session-runner-non-object-input
Open

Lushiyao5 wants to merge 1 commit into
anthropics:mainfrom
Lushiyao5:contrib/session-runner-non-object-input

Conversation

@Lushiyao5

Copy link
Copy Markdown

What

SessionToolRunner coerced every tool-call input with dict(ev.input). A tool call's input is model-produced JSON and need not be an object — a custom tool's schema can be an array. A list was silently reinterpreted as a mapping (["SF"] became {"S": "F"}), so the tool ran with corrupted arguments, and any input that is not a list of pairs raised out of the dispatch loop and aborted the whole session run.

The runner now passes an object input through as a copy and passes any other JSON through unchanged, so the tool call reports the rejection as an ordinary error result, matching the Messages runner's behavior.

Why

Tool inputs come from the model, not from trusted typed code. Silently reinterpreting them changes what the tool receives, and a raised TypeError/ValueError ends the session instead of being reported back to the model as an error result the model can react to.

How

  • _beta_session_runner.py: input_ = dict(ev.input) if is_dict(ev.input) else ev.input.
  • _tool_dispatch.py: run_runnable_tool now accepts object, since the input is forwarded as-is.
  • A custom tool that requires an object can reject the array input with a TypeError, which the runner already converts into an error result.

Tests

Added tests/lib/tools/test_session_runner.py::test_a_tool_call_whose_input_is_not_an_object_posts_an_error_and_the_runner_continues: a stream carries an array input followed by a valid object input; the first posts an error result and the second still succeeds, proving the dispatch loop keeps running.

  • pytest tests/lib/tools/test_session_runner.py → 73 passed.
  • Before the change, the array input corrupted the arguments (dict(["SF"]) → {"S": "F"}) / aborted dispatch.

Found while auditing the session runner against the Messages runner.

A tool call's `input` is model-produced JSON and need not be an object: a
custom tool's schema can be an array. `_execute` ran every input through
`dict()`, so a list was silently reinterpreted as a mapping (e.g.
`["SF"]` became `{"S": "F"}`) and the tool ran with corrupted arguments;
an input that is not a list of pairs raised out of the dispatch loop and
aborted the whole session run.

Pass an object input through as a copy and any other JSON as-is, so the
tool call reports the rejection as an error result like the Messages
runner does.
@Lushiyao5
Lushiyao5 requested a review from a team as a code owner October 31, 2026 22:13

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant