[Fix] Treat an empty grammar constraint as unset in SamplingParams (#33328)

This commit is contained in:
Liangsheng Yin
2026-08-02 21:45:51 -07:00
committed by GitHub
parent b64fd800d4
commit f5f021672a
4 changed files with 32 additions and 1 deletions
@@ -73,6 +73,16 @@ class TestSamplingParamsInit(CustomTestCase):
sp = SamplingParams(stop_token_ids=[])
self.assertIsNone(sp.stop_token_ids)
def test_empty_grammar_constraint_becomes_none(self):
"""An empty grammar string means "unset", not "constrain to nothing".
Left as "" it reads as set to the is-not-None checks downstream while
the constraint selection skips it.
"""
for field in ("json_schema", "regex", "ebnf", "structural_tag"):
with self.subTest(field=field):
sp = SamplingParams(**{field: ""})
self.assertIsNone(getattr(sp, field))
class TestSamplingParamsVerify(CustomTestCase):