Skip to content

Qwen3-Coder parser loses precision when parsing large integer tool arguments - #1967

Open
anidotdev wants to merge 1 commit into
ml-explore:mainfrom
anidotdev:fix-qwen3-coder-integer-precision
Open

anidotdev wants to merge 1 commit into
ml-explore:mainfrom
anidotdev:fix-qwen3-coder-integer-precision

Conversation

@anidotdev

@anidotdev anidotdev commented Oct 12, 2026 •

Copy link
Copy Markdown
  • ☑️ I understand it is strictly prohibited to use AI to write PR description
  • AI usage disclosure: I used AI to help inspect the repository code, and review and test the local change. I personally ran the commands, reproduced the issue, edited the files, reviewed the diff, and verified the test results. I understand the change and take responsibility for the code I eventually submit.

Description

The integer-schema branch in mlx_lm/tool_parsers/qwen3_coder.py parses param_value to a float and then to an int, which causes loss of precision for integers that can't be represented as a binary64 float.

For example, the integer literal 9007199254740993 would get parsed as 9007199254740992. The parser returns an int but the value is incorrect, the data is corrupted silently.

This could cause problems with tool parameters that are used to identify records or resources if the model emits a plain integer literal that is too big to be represented as a binary64 float.

This is a different issue from #1627 which dealt with accepting float-formatted integral values like "140.0"; this is about losing precision when parsing a plain integer literal.

Minimal Reproduction

from mlx_lm.tool_parsers import qwen3_coder

tools = [
    {
        "type": "function",
        "function": {
            "name": "lookup",
            "parameters": {
                "type": "object",
                "properties": {
                    "record_id": {"type": "integer"}
                },
                "required": ["record_id"],
            },
        },
    }
]

xml_call = (
    "<function=lookup>"
    "<parameter=record_id>9007199254740993</parameter>"
    "</function>"
)

result = qwen3_coder.parse_tool_call(xml_call, tools)
print(result["arguments"]["record_id"])

Actual result before the fix:

9007199254740992

Expected result:

9007199254740993

Environment

  • OS: Ubuntu under WSL
  • Backend: MLX CPU backend
  • Repository commit: ba8a08fd2ed72bbc53de84f89933f91fe4743e4a
  • Python: Python 3.14.4
  • MLX: mlx: 0.32.3
  • mlx-lm: mlx-lm: 0.32.1.dev15+gba8a08fd2

Tests

Before the local change:

  • The standalone regression test failed because the parser returned 9007199254740992 instead of 9007199254740993.

After the local change:

  • The focused regression test passed.
  • tests/test_tool_parsing.py passed all 20 tests.
  • Formatting checks passed for Black, isort, and Ruff.

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