Improve tool call validation strictness (#4190)

* Improve tool call validation strictness

Reject near-miss tool names without executing suggested tools. Require object-shaped tool parameters while preserving only lossless JSON wire-shape normalization.

* Tighten tool call argument validation

* Simplify tool argument validation tests

* Improve tool name suggestions

* Simplify tool suggestion helpers

* Limit tool suggestions to canonical matches

* Allow repair only for tool history replay

* Clarify non-object tool argument errors

* Inline replay tool argument normalization

* Track only successful tool executions

* Reject JSON null tool arguments
This commit is contained in:
chengyongru
2026-06-09 14:50:40 +08:00
committed by GitHub
parent f3eb2aa08b
commit 0a396aa6e2
17 changed files with 769 additions and 142 deletions
+10
View File
@@ -161,6 +161,16 @@ def test_build_kwargs_converts_messages_tools_and_tool_results() -> None:
assert kwargs["toolConfig"]["toolChoice"] == {"any": {}}
def test_tool_use_block_repairs_history_tool_arguments() -> None:
block = BedrockProvider._tool_use_block({
"id": "toolu_1",
"function": {"name": "read_file", "arguments": '{path:"foo.txt"}'},
})
assert block is not None
assert block["toolUse"]["input"] == {"path": "foo.txt"}
def test_build_kwargs_keeps_tool_config_for_historical_tool_blocks_without_tools() -> None:
provider = BedrockProvider(region="us-east-1", client=FakeClient())
messages = [