Skip to content

Python: fix(core): accept whole-number floats for JSON Schema integer type - #9852

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 4 commits into
microsoft:mainfrom
he-yufeng:fix/function-tool-integer-whole-number
Nov 3, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 4 commits into
microsoft:mainfrom
he-yufeng:fix/function-tool-integer-whole-number

Conversation

@he-yufeng

@he-yufeng Yufeng He (he-yufeng) commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #9843

Problem

_matches_json_schema_type rejects 3.0 for "integer" schema types. JSON Schema "integer" means "a number without a fraction", so whole-number floats like 3.0 are valid. A FunctionTool declared with a JSON schema rejects provider arguments containing such values with TypeError: Invalid type for 'count'.

Fix

Accept float values whose is_integer() is true alongside int, while still rejecting bool and non-whole floats like 3.5.

Testing

New test test_tool_json_schema_integer_accepts_whole_number_float:

  • 3.0 invokes without error (valid JSON Schema integer)
  • 3.5 raises TypeError (not a valid integer)
python/packages/core/tests/core/test_tools.py  152 passed

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: implementation, regression tests, and this PR description. The author reviewed the final diff and ran the targeted core tool tests.

JSON Schema 'integer' means 'a number without a fraction', so 3.0 is
valid. The _matches_json_schema_type check only accepted Python int,
rejecting 3.0 with a TypeError. Accept floats whose is_integer() is
true alongside int.

Fixes microsoft#9843
Copilot AI balanced review requested due to automatic review settings October 29, 2026 21:03
@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Oct 29, 2026
@github-actions github-actions Bot changed the title fix(core): accept whole-number floats for JSON Schema integer type Python: fix(core): accept whole-number floats for JSON Schema integer type Oct 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Accepted whole-number floats remain unconverted in integer-typed tool arguments, causing TypeError in callables that require actual integers.

1 open issue
What changed in this PR

This PR updates Python core tool validation to accept whole-number floats for JSON Schema integer parameters, addressing the validation failure reported in #9843.

Changes:

  • Accepts floats such as 3.0 while continuing to reject booleans and fractional floats.
  • Adds a regression test covering acceptance of 3.0 and rejection of 3.5.
File Description
python/​packages/​core/​tests/​core/​test_tools.py Adds coverage for whole-number and fractional float arguments.
python/​packages/​core/​agent_framework/​_tools.py Extends the integer type check to accept whole-number floats.

Review effort: Balanced

@he-yufeng

Copy link
Copy Markdown
Contributor Author

The failing check here is test_invoke_mcp_tool_executor.py on the Windows shards (assert handler.call_count == 0, getting 1 == 0). That test lives in the declarative package and exercises MCP HTTP Authorization header binding. This PR only touches python/packages/core/agent_framework/_tools.py and python/packages/core/tests/core/test_tools.py (the JSON Schema integer / whole-number-float check), so the two are unrelated.

The same test passes on the ubuntu 3.11 through 3.14 shards and only fails on the Windows shards plus 3.15, which is consistent with an environment specific or flaky test rather than this change. A pure Python type check in the core package would fail uniformly across platforms if it were the cause. Could a maintainer re-run the failed jobs when convenient?

… one

Accepting 3.0 for a JSON Schema "integer" was only half of microsoft#9843. The value was validated and then passed through unchanged, so a tool that runs range(count) or indexes with it still raised TypeError on the float the model sent. The schema declares an integer, so the callable should receive one.

_validate_arguments_against_schema now normalizes during the same top-level pass it validates in. A whole-number float becomes int when "integer" is the only numeric type allowed, which covers the plain case and the nullable one ("type": ["integer", "null"]). When "number" is allowed too the declaration permits fractions, so the value's own type is the answer and nothing is narrowed to fit a type the schema never exclusively asked for.

This is the schema-supplied path only. Tools built from Python annotations go through the input model, which already converts to the annotated types, and that path returns before these checks run.

The regression now asserts the type the callable receives rather than only that the call did not raise, and two more pin the nullable case and the number-alongside-integer one.
Merged via the queue into microsoft:main with commit 2551317 Nov 3, 2026
50 checks passed

This branch was previously deployed

1 inactive deployment
github-app-auth — 621449fc Deployed Nov 3, 2026 by he-yufeng via add_label #26908
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Schema-supplied FunctionTool rejects a whole-number float for an "integer" parameter

3 participants