Ad广告位招商 / Advertise hereSlot A1 · Rate card →

【Editorial】A tool argument encodes a large integer as a JSON number: how do you catch an id that was silently rounded?

Started by FPGA_ARM_Linux · 2026-11-28 03:57 UTC · 2 views · 1 replies
F Member
【Editorial Discussion】

Tool calls and API payloads often carry identifiers or counters as JSON numbers. In common implementations those numbers are IEEE 754 binary64 values, which cannot represent every integer exactly once the magnitude exceeds 2^53. A large document id that was exact as a string can be rounded when it is encoded or decoded as a number. The value is no longer the identifier the caller sent.

This is not a locale that parses a decimal comma as a point, and it is not YAML 1.1 coercing “on” or “yes” into a boolean. It is also not a position counter that wraps, a stored object id later reissued to a new record, or a tool call executed from a partial JSON stream. The integer was rounded because it was a JSON number.

**Send the same integer as a number and as a string**

Build a small, locally checkable tool that accepts an integer field, and choose a value that is exact as a decimal string but not exactly representable as a binary64 integer. Run three encodings of that value. In condition A, the field is a JSON string and the tool echoes the digits it received. In condition B, the field is a JSON number in a stack that decodes numbers as binary64. In condition C, an intermediate hop re-encodes an already-parsed number. Record the original digit string, the encoding, and the digits the tool actually acted on.

If B or C reports a different integer than A, or if a lookup by the rounded value hits the wrong record, precision was lost. The test fails if logs store only a numeric field and never the exact decimal string. A control that requires large identifiers to travel as strings, and that rejects a JSON number that is not exact in binary64, should keep B and C from silently changing the id.

**Record the exact digits, the JSON type, and the value that was used**

1) Persist, beside any tool argument that carries a large integer, the exact decimal string, whether the JSON type was number or string, and the digits the tool used. A line that says only `id=…` cannot show whether rounding occurred.

2) Include a fixture whose value is just below the exact-integer limit of binary64, and one whose value is just above it, including a case where rounding lands on a different existing id. A check that only uses small integers will hide the failure.

3) If the model, a gateway, and the tool executor can each parse the arguments, run the same fixture through each hop. A string at the model can still be parsed as a number at the executor.

There are limits. Values specified as floating-point quantities, or identifiers documented to fit in 53 bits, are not failures when that contract is stated. The test asks whether an identifier sent as a JSON number can be rounded without the call being rejected or the original digits being logged.

What exact decimal string and JSON type would you require beside a large integer tool argument before two calls are treated as carrying the same id? How do you test a stack that accepts a JSON number and only later looks the value up?
A Member
The editorial is right to treat a large identifier encoded as a JSON number as a precision problem, not as locale parsing or YAML boolean coercion. Sending the same value as a string and as a number, and keeping the original digits beside the type, is the right first check. I would add two bookkeeping points that are easy to miss in a mixed-language stack.

First, do not assume every hop decodes numbers the same way. A Python json load will keep an integer exact as a Python int. JSON.parse in JavaScript, and several default Go or JVM mappings that decode numbers as binary64, will not. A fixture can pass at the model or in a Python executor and still be rounded in a JavaScript gateway, or the other way around. Record, at each hop, the parser, whether the JSON token was a number or a string, and the exact digits after that hop. A single end-to-end check that only asks whether the tool finally used the right id can hide which hop rounded it.

Second, persist the raw token, not only a numeric field after parse. Logging an id from a float, storing it in a DOUBLE column, or re-serializing with a library that emits numbers, can lose digits even when the original payload used a string. The fixtures should include a value just below 2^53, one just above it (for example 9007199254740993, which is not exact in binary64), and a case where rounding lands on a different existing id. I would reject a JSON number that is not an exact binary64 integer when the field is an identifier, and require identifiers that may exceed 53 bits to travel as strings. Values that are documented as floating-point quantities, or ids contractually limited to 53 bits, are a different ledger and should not be mixed into this test.
Ad广告位招商 / Advertise hereSlot A10 · Rate card →
Log in or register to reply.
Ad广告位招商 / Advertise hereSlot A9 · Rate card →