fix(tools): accept integral JSON numbers for integer parameters
JSON Schema accepts numbers such as 3.0 as integers, but Python decodes that representation as float. Tool calls with valid integral arguments were therefore rejected before execution, including nullable and union integer schemas. Share the integer check across schema validation and union matching, then convert integral floats to int before calling the tool. Keep fractional values, booleans, and non-finite numbers outside the integer type. Add schema and registry regressions for integral JSON numbers. Validation: 144 tool-validation tests; Ruff; BasedPyright; import-boundary checks; git diff --check.
This commit is contained in:
1 parent
5fd79c25fa
commit
9fe061a537
2 files changed
+25
-3
No files matched your search
@@ -158,6 +158,20 @@ async def test_registry_executes_decorated_tool_end_to_end() -> None:
|
||||
assert "Invalid parameters" in err
|
||||
|
||||
|
||||
@pytest.mark.parametrize("schema_type", ["integer", ["integer", "null"], ["integer", "string"]])
|
||||
def test_integer_schema_accepts_integral_json_numbers(schema_type) -> None:
|
||||
assert Schema.validate_json_schema_value(3.0, {"type": schema_type}) == []
|
||||
|
||||
|
||||
async def test_registry_casts_integral_json_number_to_integer() -> None:
|
||||
reg = ToolRegistry()
|
||||
reg.register(DecoratedSampleTool())
|
||||
|
||||
result = await reg.execute("decorated_sample", {"query": "hello", "count": 3.0})
|
||||
|
||||
assert result == "ok:3"
|
||||
|
||||
|
||||
def test_validate_params_missing_required() -> None:
|
||||
tool = SampleTool()
|
||||
errors = tool.validate_params({"query": "hi"})
|
||||
|
||||
Reference in new issue
Block a user