Skip to content

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

Closed

Description

Observed Behavior

A FunctionTool declared with a JSON schema (input_model given as a mapping) validates the provider's arguments with _validate_arguments_against_schema, whose check for "integer" is

case "integer":
    return isinstance(value, int) and not isinstance(value, bool)

(python/packages/core/agent_framework/_tools.py, _matches_json_schema_type, lines 1601-1602 on main at 9ef8672; the same lines ship in 1.22.0 and 1.23.0). A value of 3.0 fails with Invalid type for 'count' in 'count_things': expected integer, got float. In the automatic function-calling loop the model receives Error: Argument parsing failed. (with that detail when include_detailed_errors is on) and spends one more round trip and one of max_iterations to retry with 3.

The same arguments through a Pydantic input_model (count: int) are accepted: 3.0 arrives as 3. So whether 3.0 is a valid integer depends on how the tool was declared, not on the schema the model was shown. Tools taken from MCP servers arrive as schemas, so this is their path.

Seen live on 2026-10-29: Qwen3.5-122B behind vLLM 0.32.0 sent num_results: 3.0 on its first web-search call in 2 of 2 turns that used the tool. Each cost one extra model call and one iteration of the loop; the retry with 3 succeeded.

Expected Behavior

3.0 passes the integer check and reaches the function as 3, as the Pydantic path already delivers it. JSON Schema Validation 2020-12, section 6.1.1, defines integer as matching "any number with a zero fractional part" (https://json-schema.org/draft/2020-12/json-schema-validation.html). 2.5 and True keep failing.

Steps to Reproduce

  1. Install agent-framework-core==1.22.0 or ==1.23.0 (Python 3.12).
  2. Run the script below.
  3. Observe the second line of each block: the schema-declared tool rejects 3.0, the Pydantic-declared tool accepts it.

Minimal Reproduction

import asyncio

from pydantic import BaseModel

from agent_framework import FunctionTool

schema = {"type": "object", "properties": {"count": {"type": "integer"}}, "required": ["count"]}


class Args(BaseModel):
    count: int


async def count_things(count):
    return f"received {count!r} ({type(count).__name__})"


async def main():
    for label, model in (("schema dict", schema), ("pydantic model", Args)):
        tool = FunctionTool(name="count_things", description="counts", func=count_things, input_model=model)
        for value in (3, 3.0, 2.5, True):
            try:
                result = await tool.invoke(arguments={"count": value})
                print(f"{label:14} {value!r:5} -> {result[0].text}")
            except Exception as exc:
                print(f"{label:14} {value!r:5} -> {type(exc).__name__}: {str(exc).splitlines()[0]}")


asyncio.run(main())

Error Messages and Stack Traces

agent-framework-core 1.23.0
schema dict    3     -> received 3 (int)
schema dict    3.0   -> _FunctionArgumentValidationError: Invalid type for 'count' in 'count_things': expected integer, got float
schema dict    2.5   -> _FunctionArgumentValidationError: Invalid type for 'count' in 'count_things': expected integer, got float
schema dict    True  -> _FunctionArgumentValidationError: Invalid type for 'count' in 'count_things': expected integer, got bool
pydantic model 3     -> received 3 (int)
pydantic model 3.0   -> received 3 (int)
pydantic model 2.5   -> _FunctionArgumentValidationError: Invalid arguments for 'count_things': 1 validation error for Args
pydantic model True  -> received 1 (int)

The output on 1.22.0 is identical.

Package Versions

agent-framework-core: 1.22.0 and 1.23.0 (both run); main at 9ef8672 carries the same check

Python Version

Python 3.12

Operating System

macOS (reproduction); Linux (the live loop)

Regression

Unknown

Additional Context

A fix that follows the schema: in _matches_json_schema_type, count a float with a zero fractional part (value.is_integer()) as an integer, booleans still excluded, and have _validate_arguments_against_schema hand the function int(value) for an integer property, so both declaration paths deliver the same Python type. Tests worth having: 3.0 accepted as 3; 2.5 and True rejected; 3.0 accepted for "type": ["integer", "null"].

Until a release carries a fix we bridge with function middleware that repairs the value before the final check, the path _tools.py itself points to ("Install argument-repair middleware before security middleware").

Acknowledgements

  • I searched existing issues and did not find a duplicate.
  • I personally verified this behavior and the reproduction details are authentic.
  • I will wait for explicit maintainer agreement before starting implementation of a non-trivial change.

Activity

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Oct 29, 2026
  2. added
    reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
    on Oct 29, 2026
  3. github-actions commented on Oct 29, 2026

    @github-actions
    Contributor

    🤖 Automated triage reproduction notes (agent-authored — trust but verify)

    Agent analysis

    The bug occurs in python/packages/core/agent_framework/_tools.py::_matches_json_schema_type, reached through _validate_arguments_against_schema, when a schema-supplied integer receives a whole-number float such as 3.0. Minimal repro: construct a FunctionTool with mapping input schema {"count": {"type": "integer"}} and invoke it with {"count": 3.0}; validation raises _FunctionArgumentValidationError before execution.

    • Failing test: python/packages/core/tests/core/test_tools.py::test_function_tool_with_json_schema_accepts_whole_number_float_for_integer
    • Files examined: python/packages/core/agent_framework/_tools.py, python/packages/core/agent_framework/_mcp.py, python/packages/core/tests/core/test_tools.py, python/packages/core/pyproject.toml
    • Tests run: three existing JSON-schema invocation tests, test_function_tool_with_json_schema_accepts_whole_number_float_for_integer
    • Reported version: agent-framework-core 1.22.0 and 1.23.0
    • Current version: agent-framework-core 1.23.0
  4. added
    agentsUsage: [Issues, PRs], Target: Single agent
    mcpUsage: [Issues, PRs], Target: MCP
    and removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Oct 29, 2026
  5. danielquintas8 commented on Oct 29, 2026

    @danielquintas8
    Author

    I'll take on implementing this as described under Expected Behavior. A float with a zero fractional part would pass the integer check and reach the function as an int, the value the Pydantic path already delivers. Fractional values and booleans would still be rejected, and type lists such as ["integer", "null"] would get the same treatment.

    Eduard van Valkenburg (@eavanvalkenburg), before I open a PR, can you confirm that the function should receive an int? If the check only accepted 3.0 and passed it on unchanged, a tool that calls range(count) or indexes a list with count would still raise TypeError.

    This is the change I have in mind, against main at 4d28d0a:

    --- a/python/packages/core/agent_framework/_tools.py
    +++ b/python/packages/core/agent_framework/_tools.py
    @@ -1593,13 +1593,18 @@
         return annotation
     
     
    +def _is_whole_float(value: Any) -> bool:
    +    """A float with a zero fractional part, which JSON Schema counts as an integer."""
    +    return isinstance(value, float) and value.is_integer()
    +
    +
     def _matches_json_schema_type(value: Any, schema_type: str) -> bool:
         """Check a value against a simple JSON schema primitive type."""
         match schema_type:
             case "string":
                 return isinstance(value, str)
             case "integer":
    -            return isinstance(value, int) and not isinstance(value, bool)
    +            return (isinstance(value, int) and not isinstance(value, bool)) or _is_whole_float(value)
             case "number":
                 return (isinstance(value, int | float)) and not isinstance(value, bool)
             case "boolean":
    @@ -1649,6 +1654,8 @@
                         f"Invalid type for '{field_name}' in '{tool_name}': "
                         f"expected {schema_type}, got {type(field_value).__name__}"
                     )
    +            if schema_type == "integer" and _is_whole_float(field_value):
    +                parsed_arguments[field_name] = int(field_value)
                 continue
     
             if isinstance(schema_type, list):
    @@ -1658,6 +1665,8 @@
                         f"Invalid type for '{field_name}' in '{tool_name}': expected one of "
                         f"{allowed_types}, got {type(field_value).__name__}"
                     )
    +            if "integer" in allowed_types and "number" not in allowed_types and _is_whole_float(field_value):
    +                parsed_arguments[field_name] = int(field_value)
     
         return parsed_arguments
     

    A type list that also allows number keeps the float, because the value is already valid there as it is. I ran this on 1.23.0, whose two functions are identical to main's. 3.0 reaches the function as 3 for integer, for ["integer", "null"] and with an enum, and a tool that calls range(count) works. 2.5, True and inf are still rejected. The PR would add tests for these cases, including one that a schema-declared tool and a Pydantic-declared tool hand the function the same 3 for 3.0.

  6. eavanvalkenburg commented on Nov 2, 2026

    @eavanvalkenburg
    Member

    /plan Plan the schema-supplied FunctionTool whole-number-float integer mismatch, coordinating existing #9852 and the reporter proposal rather than starting competing implementations. Current validation rejects 3.0 despite JSON Schema integer semantics; accepting it alone does not settle the Python type passed to a callable such as range(count). Decide and document the callable-observable normalization contract versus acceptance-only behavior, including integer/null and integer/number unions, enums, booleans, fractional/nonfinite values and Pydantic-path differences. Preserve already-valid number values and intentional boolean rejection; keep scope to the existing supported top-level mapping-schema checks rather than introduce a general schema/coercion engine. Cross-check the function-calling-loop contract and argument-repair/security middleware ordering; test actual FunctionTool invocation, not only the primitive predicate, including schema-derived MCP tools where applicable. Existing PR currently addresses acceptance but not the reporter requested int delivery, so do not mark it minor-ready or assign until this behavior is agreed.

  7. danielquintas8 commented on Nov 2, 2026

    @danielquintas8
    Author

    Eduard van Valkenburg (@eavanvalkenburg), I want to raise a concern about the contribution process. This is the second issue I’ve reported where someone opened a PR before maintainer agreement was recorded on the issue.

    On 22 October, the author of #9573 acknowledged that neither it nor their other two PRs had maintainer agreement. On 28 October, you also asked the author of #9852 for an agreed issue or a justified trivial-change exception on #9547, before #9852 opened.

    I asked for confirmation before opening my own PR. If another implementation proceeds while I wait and becomes the basis for further work, it becomes hard to justify offering fixes through the issue-first process. It makes me less willing to report issues.

    Your plan already withholds readiness and assignment while the behavior is agreed. Could you clarify how PRs opened before that agreement will be handled? I’d like to see the requirement applied consistently before implementation review, so contributors who wait are not disadvantaged by following the process.

  8. eavanvalkenburg commented on Nov 3, 2026

    @eavanvalkenburg
    Member

    Maintainer decision for #9843: accept whole-number floats as JSON Schema integers and normalize them to Python int before invocation for integer-only and integer | null schemas. Preserve the float when number is also allowed, and continue rejecting booleans, fractional values, and non-finite values. Keep scope to the existing top-level mapping-schema validation. #9852 matches this contract. Daniel Quintas (@danielquintas8), thank you for reporting the issue and waiting for direction; this comment records the agreed behavior and coordination decision.

  9. added a commit that references this issue on Nov 3, 2026
    2551317
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agentsUsage: [Issues, PRs], Target: Single agentmcpUsage: [Issues, PRs], Target: MCPpythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions