sgl-project/sglang · error · ValueError
think_end_token '{reasoning_parser.detector.think_end_token}
Error message
think_end_token '{reasoning_parser.detector.think_end_token}' could not be encoded by the tokenizer. What it means
ReasonerGrammarBackend encodes the reasoning parser's think-end marker (e.g. '</think>') with the model tokenizer; if encoding yields no token IDs, it raises ValueError because strict reasoning enforcement cannot detect the end of thinking.
Source
Thrown at python/sglang/srt/constrained/reasoner_grammar_backend.py:257
old_output_ids, new_output_ids, next_state
)
class ReasonerGrammarBackend(BaseGrammarBackend):
def __init__(
self,
grammar_backend: BaseGrammarBackend,
reasoning_parser: ReasoningParser,
tokenizer: Union[PreTrainedTokenizer, PreTrainedTokenizerFast],
enable_strict_thinking: bool = False,
):
super().__init__()
self.grammar_backend = grammar_backend
think_end_ids = tokenizer.encode(
reasoning_parser.detector.think_end_token, add_special_tokens=False
)
if not think_end_ids:
raise ValueError(
f"think_end_token '{reasoning_parser.detector.think_end_token}' "
f"could not be encoded by the tokenizer."
)
self.think_end_ids = think_end_ids
self._enable_strict_thinking = enable_strict_thinking
self.think_excluded_token_ids = self._get_think_excluded_token_ids(
reasoning_parser, tokenizer
)
self.max_think_tokens = envs.SGLANG_MAX_THINK_TOKENS.get()
self.enable_token_filter = self.enable_strict_thinking and (
self.think_excluded_token_ids is not None or self.max_think_tokens >= 0
)
if (
self.enable_token_filter
and not self.grammar_backend.is_support_token_filter
):
raise ValueError(
"Strict reasoning format requested but the grammar backend does not "View on GitHub (pinned to 0132848349)
Solutions
- Verify reasoning_parser.detector.think_end_token is set to the correct literal (e.g. '</think>') for the model
- Test tokenizer.encode(think_end_token, add_special_tokens=False) manually; if empty, fix the tokenizer/parser config
- Use a different --reasoning-parser value matching the model
Defensive patterns
Strategy: validation
Validate before calling
ids = tokenizer.encode(parser.detector.think_end_token, add_special_tokens=False) assert ids, 'think_end_token not encodable by this tokenizer'
Prevention
- Add a startup assertion for reasoning-parser markers on new model integrations
- Unit-test detector marker tokens against the model tokenizer in CI
When it happens
Trigger: Constructing ReasonerGrammarBackend where reasoning_parser.detector.think_end_token is empty or not representable by the tokenizer (yields zero tokens with add_special_tokens=False).
Common situations: Custom reasoning parsers with a misconfigured think_end_token; tokenizers whose vocab genuinely lacks pieces for the marker; empty-string detector fields on new model integrations.
Related errors
- think_excluded_token '{token}' could not be encoded by the t
- --enable-strict-thinking requires a grammar backend with tok
- --enable-strict-thinking requires a grammar backend that sup
- Invalid grammar backend: {name}
- Strict reasoning format requested but the grammar backend do
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/5aaf461dcd5170db.
Report an issue: GitHub.