{"record":{"id":"577a650ccd80e1c0","repo":"sgl-project/sglang","slug":"strict-reasoning-format-requested-but-the-grammar","errorCode":null,"errorMessage":"Strict reasoning format requested but the grammar backend does not support token filtering. Use a grammar backend that supports token filtering (e.g., xgrammar) or disable strict reasoning mode.","messagePattern":"Strict reasoning format requested but the grammar backend does not support token filtering\\. Use a grammar backend that supports token filtering \\(e\\.g\\., xgrammar\\) or disable strict reasoning mode\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/constrained/reasoner_grammar_backend.py","lineNumber":274,"sourceCode":"        if not think_end_ids:\n            raise ValueError(\n                f\"think_end_token '{reasoning_parser.detector.think_end_token}' \"\n                f\"could not be encoded by the tokenizer.\"\n            )\n        self.think_end_ids = think_end_ids\n        self._enable_strict_thinking = enable_strict_thinking\n        self.think_excluded_token_ids = self._get_think_excluded_token_ids(\n            reasoning_parser, tokenizer\n        )\n        self.max_think_tokens = envs.SGLANG_MAX_THINK_TOKENS.get()\n        self.enable_token_filter = self.enable_strict_thinking and (\n            self.think_excluded_token_ids is not None or self.max_think_tokens >= 0\n        )\n        if (\n            self.enable_token_filter\n            and not self.grammar_backend.is_support_token_filter\n        ):\n            raise ValueError(\n                \"Strict reasoning format requested but the grammar backend does not \"\n                \"support token filtering. Use a grammar backend that supports token \"\n                \"filtering (e.g., xgrammar) or disable strict reasoning mode.\"\n            )\n        self._token_filter_fn = (\n            self.grammar_backend.set_token_filter if self.enable_token_filter else None\n        )\n\n    def _get_think_excluded_token_ids(\n        self,\n        reasoning_parser: ReasoningParser,\n        tokenizer: Union[PreTrainedTokenizer, PreTrainedTokenizerFast],\n    ) -> Optional[List[int]]:\n        excluded_ids = []\n        if (not self.enable_strict_thinking) or (\n            not reasoning_parser.detector.think_excluded_tokens\n        ):\n            return None","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/constrained/reasoner_grammar_backend.py#L256-L292","documentation":"ReasonerGrammarBackend needs the wrapped grammar backend's token-filter capability to enforce strict reasoning format; if enable_token_filter is on but grammar_backend.is_support_token_filter is False, it raises this ValueError at construction.","triggerScenarios":"Wrapping a backend without token filtering (e.g. 'none' or a backend lacking set_token_filter) while strict reasoning options (think_excluded tokens or max_think_tokens) request filtering.","commonSituations":"Using --grammar-backend llguidance/none with strict thinking flags; custom grammar backends that don't implement set_token_filter.","solutions":["Switch to --grammar-backend xgrammar, which supports token filtering","Disable strict reasoning mode (drop think-excluded-token / max-think-token enforcement flags)","If implementing a custom backend, add is_support_token_filter=True and a set_token_filter method"],"exampleFix":"# before\n--grammar-backend none --max-think-tokens 1024\n# after\n--grammar-backend xgrammar --max-think-tokens 1024","handlingStrategy":"validation","validationCode":"if strict_reasoning_enabled:\n    assert grammar_backend.is_support_token_filter, 'backend must support token filtering'","typeGuard":"def supports_token_filter(b) -> bool:\n    return bool(getattr(b, 'is_support_token_filter', False))","tryCatchPattern":null,"preventionTips":["Check is_support_token_filter before wrapping backends with strict reasoning options","Register capability flags on custom backends explicitly"],"tags":["reasoning","grammar","configuration"],"backgroundTag":"feature-requires-unsupported-backend","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}