fix: propagate grammar errors and improve llguidance backend#20467
Merged
hnyls2002 merged 7 commits intosgl-project:mainfrom Mar 15, 2026
Merged
fix: propagate grammar errors and improve llguidance backend#20467hnyls2002 merged 7 commits intosgl-project:mainfrom
hnyls2002 merged 7 commits intosgl-project:mainfrom
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
hnyls2002
approved these changes
Mar 12, 2026
Collaborator
|
/tag-and-rerun-ci |
hnyls2002
requested changes
Mar 12, 2026
Contributor
Author
I ran |
Collaborator
|
/rerun-ut test_constrained_decoding_spec_reasoning.py |
Contributor
|
❌ Please ask a maintainer to add the |
hnyls2002
approved these changes
Mar 15, 2026
Wangzheee
pushed a commit
to Wangzheee/sglang
that referenced
this pull request
Mar 21, 2026
0-693
pushed a commit
to 0-693/sglang
that referenced
this pull request
Mar 25, 2026
JustinTong0323
pushed a commit
to JustinTong0323/sglang
that referenced
this pull request
Apr 7, 2026
yhyang201
pushed a commit
to yhyang201/sglang
that referenced
this pull request
Apr 22, 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
This PR addresses two related issues:
Opaque error messages on invalid grammars: When a grammar fails to compile, the original error from the backend is only logged server-side. The user receives a generic message like
"Invalid grammar request"with no indication of what actually went wrong.Silent failures and missing features in llguidance backend: When an invalid schema is provided, the matcher is created in an error state but this wasn't being checked. Generation would proceed and return empty output with no error indication. Additionally,
rollback()was not implemented, causing speculative decoding to fail.Modifications
Error propagation across all grammar backends:
InvalidGrammarObject(BaseGrammarObject)class inbase_grammar_backend.pywith anerror_messagefield to carry the original compilation errorINVALID_GRAMMAR_OBJsentinel returns withInvalidGrammarObjectin all backendsgrammar_manager.pyto useInvalidGrammarObjectand includeerror_messagein user-facing abort messagesreasoner_grammar_backend.pyto useInvalidGrammarObjectImproved error message format:
Invalid grammar request: req.grammar_key=('json', '{"type": "strng"}')) with a clean, user-friendly format:Failed to compile json grammar: JSON schema has unsupported type 'strng'llguidance backend improvements:
_check_err()helper method that validates matcher state and raises descriptive errors__init__()accept_token,rollback,fill_vocab_mask)rollback()method with proper EOS token handling for speculative decodingis_terminated()methodAccuracy Tests
Benchmarking and Profiling
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci