Skip to content

[Fix] Work around xgrammar 0.2.1 negative integer minimum in Kimi-K3 structural tags - #34778

Merged
hnyls2002 merged 1 commit into
sgl-project:mainfrom
gilfordting:fix/kimik3-negative-int-minimum
Aug 14, 2026
Merged

hnyls2002 merged 1 commit into
sgl-project:mainfrom
gilfordting:fix/kimik3-negative-int-minimum

Conversation

@gilfordting

@gilfordting gilfordting commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

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 (no maximum/exclusiveMaximum/multipleOf), split the range at zero into anyOf: [{... maximum: -1}, {... minimum: 0}]. Semantically identical schema, but each branch is a form the converter compiles correctly. Schemas with an upper bound or multipleOf are 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

@gongy

gongy commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

/rerun-test test_protocol.py test_json_mode.py test_constrained_decoding.py

@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_protocol.py test_json_mode.py test_constrained_decoding.py:

🚀 ubuntu-latest (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/entrypoints/openai/test_protocol.py

🚀 1-gpu-5090 (1 test): ✅ View workflow run

cd test/ && python3 registered/constrained_decoding/test_constrained_decoding.py

test_json_mode.py: No test file found matching test_json_mode.py under test/registered/ or python/sglang/multimodal_gen/test/.

@gongy

gongy commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

/rerun-test test/registered/unit/function_call/test_json_schema_constraint.py

@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/unit/function_call/test_json_schema_constraint.py:

🚀 ubuntu-latest (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/function_call/test_json_schema_constraint.py

@hnyls2002
hnyls2002 merged commit 3f64f14 into sgl-project:main Aug 14, 2026
105 of 121 checks passed
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>
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.

4 participants