{"record":{"id":"55c424669a58968c","repo":"sgl-project/sglang","slug":"enable-strict-thinking-requires-a-grammar-backen","errorCode":null,"errorMessage":"--enable-strict-thinking requires a grammar backend with token filtering support, but XGrammar failed to initialize: {e}. Cannot fall back to grammar_backend='none' with strict thinking enabled.","messagePattern":"--enable-strict-thinking requires a grammar backend with token filtering support, but XGrammar failed to initialize: (.+?)\\. Cannot fall back to grammar_backend='none' with strict thinking enabled\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"python/sglang/srt/constrained/base_grammar_backend.py","lineNumber":392,"sourceCode":"    elif name == \"xgrammar\":\n        from sglang.srt.constrained.xgrammar_backend import (\n            TokenizerNotSupportedError,\n            XGrammarGrammarBackend,\n        )\n\n        # Convert Set[int] to List[int] if needed\n        eos_list = list(eos_token_ids) if eos_token_ids else None\n\n        try:\n            grammar_backend = XGrammarGrammarBackend(\n                tokenizer,\n                vocab_size=vocab_size,\n                model_eos_token_ids=eos_list,\n                any_whitespace=not get_serving().constrained_json_disable_any_whitespace,\n            )\n        except TokenizerNotSupportedError as e:\n            if get_serving().enable_strict_thinking:\n                raise ValueError(\n                    f\"--enable-strict-thinking requires a grammar backend with \"\n                    f\"token filtering support, but XGrammar failed to initialize: \"\n                    f\"{e}. Cannot fall back to grammar_backend='none' with strict \"\n                    f\"thinking enabled.\"\n                ) from e\n            logger.warning(\n                f\"Grammar backend disabled because tokenizer is not supported by XGrammar: {e}. \"\n                \"Falling back to grammar_backend='none'. \"\n                \"Structured outputs (JSON schema, regex, EBNF) will not be available.\"\n            )\n            get_context().override(\"grammar.import_fallback\", grammar_backend=\"none\")\n            return None\n    elif name == \"llguidance\":\n        from sglang.srt.constrained.llguidance_backend import GuidanceBackend\n\n        grammar_backend = GuidanceBackend(\n            tokenizer=tokenizer,\n            any_whitespace=not get_serving().constrained_json_disable_any_whitespace,","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/constrained/base_grammar_backend.py#L374-L410","documentation":"With --enable-strict-thinking, SGLang needs a grammar backend that supports token filtering. If the XGrammar backend fails to initialize (TokenizerNotSupportedError), create_grammar_backend refuses to silently fall back to no grammar backend and raises this ValueError.","triggerScenarios":"Launching the server with --enable-strict-thinking (and default xgrammar grammar backend) where the model's tokenizer cannot be turned into an XGrammar TokenizerInfo (e.g. unusual tokenizer type or failed from_huggingface conversion).","commonSituations":"New or exotic tokenizer architectures unsupported by xgrammar; version mismatch between transformers/xgrammar; strict-thinking feature enabled on a model whose tokenizer lacks xgrammar support.","solutions":["Remove --enable-strict-thinking if strict reasoning-format enforcement is not required","Switch to a model whose tokenizer is supported by XGrammar (standard BPE/SentencePiece HF tokenizers)","Upgrade xgrammar and transformers; check the chained cause '{e}' for the underlying tokenizer conversion failure"],"exampleFix":"# before\npython -m sglang.launch_server --model ... --enable-strict-thinking\n# after\npython -m sglang.launch_server --model ...  # no strict thinking, or use an xgrammar-compatible model","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    backend = create_grammar_backend(args)\nexcept ValueError as e:\n    if 'strict-thinking' in str(e):\n        logging.error('Disable --enable-strict-thinking or use an xgrammar-compatible tokenizer')\n    raise","preventionTips":["Smoke-test create_grammar_backend at startup with your model before enabling strict thinking","Pin xgrammar/transformers versions validated for your model family"],"tags":["grammar","strict-thinking","xgrammar","startup"],"backgroundTag":"feature-requires-unsupported-backend","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}