[Fix] Work around xgrammar 0.2.1 negative integer minimum in Kimi-K3 structural tags - #34778
Merged
hnyls2002 merged 1 commit intoAug 14, 2026
Merged
Conversation
Collaborator
|
/rerun-test test_protocol.py test_json_mode.py test_constrained_decoding.py |
Contributor
|
Results for 🚀 🚀 ⛔ |
Collaborator
|
/rerun-test test/registered/unit/function_call/test_json_schema_constraint.py |
Contributor
|
Results for 🚀 |
saturn-acc
pushed a commit
to saturn-acc/sglang
that referenced
this pull request
Aug 16, 2026
…structural tags (sgl-project#34778) Co-authored-by: James Liu <jamesl@modal.com>
Atituiset
pushed a commit
to Atituiset/sglang
that referenced
this pull request
Sep 10, 2026
…structural tags (sgl-project#34778) Co-authored-by: James Liu <jamesl@modal.com>
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
XGrammar 0.2.1 (the version pinned in
python/pyproject.toml) miscompiles a JSON schema integer with a one-sided negative lower bound:{"type": "integer", "minimum": -N}produces a grammar that accepts the incomplete literal"-"and rejects every valid negative integer. Any Kimi-K3 tool whose parameter schema uses such a bound gets structurally-invalid tool calls under constrained decoding.Modifications
kimik3_structural_tag.py::_value_format: when an integer schema has only a negative lower bound (nomaximum/exclusiveMaximum/multipleOf), split the range at zero intoanyOf: [{... maximum: -1}, {... minimum: 0}]. Semantically identical schema, but each branch is a form the converter compiles correctly. Schemas with an upper bound ormultipleOfare left untouched.Unit tests cover the rewrite and the untouched cases (
test_kimik3_structural_tag.py, runs against the real pinned xgrammar).This is deliberately scoped as a converter-side workaround; the underlying bug belongs to xgrammar's JSON-schema-to-grammar conversion and the workaround can be dropped once the pin moves past a fixed release.
Accuracy Tests
N/A — affects only grammar compilation for constrained tool-call decoding; the accepted language is the schema's original semantics.
Speed Tests and Profiling
N/A.
Checklist
🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ❌ Run #31746756454
Latest PR Test (Extra): ❌ Run #31746756300