Skip to content

Read JSON literals the argument schema admits under combinators - #535

Merged
jonathan308 merged 3 commits into
mainfrom
fix/tool-argument-literals-under-combinators
Nov 24, 2026
Merged

jonathan308 merged 3 commits into
mainfrom
fix/tool-argument-literals-under-combinators

Conversation

@jonathan308

Copy link
Copy Markdown

Summary

ToolArgumentNormalization kept the text of any value whose schema had no single non-string type: not, if/then/else, a union that admits a string, or no type. So an XML parameter value -2500 under {"not": {"type": "string"}} stayed the string "-2500", which the schema rejects.

A three-valued check now reads whether the schema admits a scalar: type, nullable, enum, const, numeric and string bounds, pattern, not, allOf, anyOf, oneOf, if/then/else, and local references within the existing budget.

  • A text that spells a JSON literal becomes that literal when the schema admits it and rejects the text as a string.
  • In the XML dialects, where every value is text, a number also wins when both readings are admitted and the text is its exact JSON spelling, so 001 or +5 stay text.
  • Anything the check cannot decide keeps the text. keepsText agrees, so a streamed value is held whenever a literal could replace it.
Commit What it does
4a736b32c2 Tests: JSON literals under combinator and untyped schemas
689f2f00bf The scalar-admission check and its use in normalization

Test plan

  • SDK tests pass locally (300 tests, 26 suites).
  • Red control (draft PR, the test commit alone on main): fails the new tests.
  • Fork Tests, Lint and Fork Diff Check on the exact head.

AI usage

  • I have read this PR description in full and approve it as my own, and it
    accurately describes the code changes.
  • AI usage disclosure: an AI model (Claude Opus 5.5, in OpenCode) wrote this change, its tests and this description, and opened this PR on the repository owner's behalf under the owner's authorization for this release. The acknowledgement box above is left for the owner.

XML parameter values are unquoted text. Under a schema with no single
non-string type, such as {"not": {"type": "string"}}, an
if/then/else that picks integer or string, a type union, or no type at
all, a value such as -2500 should read as the number the schema admits.
A quoted JSON string should change only when the schema rejects every
string.
ToolArgumentNormalization kept the text of any value whose schema had
no single non-string type: not, if/then/else, a union that admits a
string, or no type. So an XML value -2500 under {"not": {"type":
"string"}} stayed the string "-2500", which the schema rejects.

A three-valued check now reads whether the schema admits a scalar
(type, nullable, enum, const, numeric and string bounds, pattern, not,
allOf, anyOf, oneOf, if/then/else, local references within the existing
budget). A text that spells a JSON literal becomes that literal when the
schema admits it and rejects the text as a string. In the XML dialects,
where every value is text, a number also wins when both readings are
admitted and the text is its exact JSON spelling, so 001 or +5 stay
text. Anything the check cannot decide keeps the text. keepsText now
agrees, so a streamed value is held whenever a literal could replace it.
Gemma marks a string value explicitly, and its numeric typing of those
values is opt-in (DARKBLOOM_GEMMA_SCHEMA_COERCION). The literal reading
added for combinator and untyped schemas also reached Gemma through
numericReading and convertParameterValue, so with the switch on a quoted
"3" under anyOf integer or boolean became 3. Gemma now passes a policy
that never reads such a literal, as before, and a test pins its values
under string-rejecting schemas.
@jonathan308
jonathan308 merged commit cba8c22 into main Nov 24, 2026
34 checks passed
jonathan308 added a commit to Layr-Labs/d-inference that referenced this pull request Nov 24, 2026
Moves the SDK pin from 689f2f00bf to cba8c22177, the merge commit that landed Layr-Labs/mlx-swift-lm#535 on main. Its tree is #535's tree on main 52f81662a6.
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