Repository navigation
[Fix] kimi-k3: Resolve strict tool $refs into the root parameters schema - #48357
Merged
Merged
Conversation
The Kimi-K3 structural tag compiles each argument value as its own JSON schema. A $ref into the root structure, such as "#/properties/value/properties/a", is then looked up in the argument schema, which no longer has that path, and the grammar fails to compile, so the request gets a 400. Before compiling an argument, copy every root-structure ref target (and, transitively, the root-structure refs inside it) under the argument's $defs and rewrite the ref to it. Refs into $defs/definitions already resolve, since every argument schema carries the root's pools, and are left alone.
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
Collaborator
Author
|
/tag-and-rerun-ci |
Collaborator
Author
|
/rerun-test test_kimik3_structural_tag.py test_kimik3_detector.py test_function_call_parser.py test_serving_chat.py |
Contributor
|
🚀 |
41 of 42 tasks
This was referenced Nov 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
A Kimi-K3 request with a strict tool fails with HTTP 400 when the tool's
parametersuse a$refthat points into the root structure instead of into$defs:{ "type": "object", "required": ["value"], "properties": { "value": { "type": "object", "properties": { "a": {"type": "string"}, "b": {"$ref": "#/properties/value/properties/a"} } } } }The Kimi-K3 tool-call format emits each argument separately, so the structural tag compiles each argument value as its own JSON schema. A ref such as
#/properties/value/...is then resolved against the argument schema, which no longer has that path. Refs into$defs/definitionsare unaffected, because every argument schema already carries the root's definition pools.Modifications
All changes are in
function_call/kimik3_structural_tag.py:_is_root_structure_reftells a local ref into the root structure apart from a ref into$defs/definitions._localize_root_refscopies every root-structure ref target into the argument schema's$defsunder a freshroot_ref_<n>name and rewrites the ref to point there._argument_value_variantsapplies it to each type-restricted argument schema before compiling it. A schema without root-structure refs is returned unchanged.Tests
test_kimik3_structural_tag.pygains two tests:test_strict_schema_resolves_refs_into_the_root_structurecovers three kinds of ref:items,$defsand root-structure refs.test_strict_schema_resolves_recursive_root_structure_refscovers anitemsref back to the argument itself.Each test checks that a valid value is accepted and a wrongly typed one is rejected. Both tests fail on main and pass here with the pinned xgrammar 0.2.7. The rest of
test/registered/unit/function_call/gives the same results before and after the change.CI States
Latest PR Test (Base): 🚫 Run #41800920928
Latest PR Test (Extra): ❌ Run #41800920680
Latest PR Test (AMD ROCm 10): 🚫 Run #41800920710
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: