{"record":{"id":"c21903c20be23af6","repo":"sgl-project/sglang","slug":"default-chat-template-kwargs-must-decode-to-a-js","errorCode":null,"errorMessage":"--default-chat-template-kwargs must decode to a JSON object","messagePattern":"--default-chat-template-kwargs must decode to a JSON object","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/server_args.py","lineNumber":9574,"sourceCode":"                f\"(got {cfg.asr_max_buffer_seconds}).\"\n            )\n        if cfg.asr_max_concurrent_sessions <= 0:\n            raise ValueError(\n                f\"--asr-max-concurrent-sessions must be positive \"\n                f\"(got {cfg.asr_max_concurrent_sessions}).\"\n            )\n\n    def _validate_prefill_decode_interval(self):\n        cfg = resolving_view(self)\n        if cfg.prefill_decode_interval < 0:\n            raise ValueError(\"--prefill-decode-interval must be non-negative.\")\n\n    def _handle_other_validations(self):\n        cfg = resolving_view(self)\n        if cfg.default_chat_template_kwargs is not None and not isinstance(\n            cfg.default_chat_template_kwargs, dict\n        ):\n            raise ValueError(\n                \"--default-chat-template-kwargs must decode to a JSON object\"\n            )\n\n        # Handle optimistic prefill validation\n        if cfg.optimistic_prefill_attempts > 0 and cfg.disaggregation_mode == \"prefill\":\n            if cfg.pp_size > 1:\n                logger.warning(\"Optimistic prefill does not support pp_size > 1\")\n                self._declare(\n                    \"_handle_other_validations\",\n                    optimistic_prefill_attempts=0,\n                )\n            elif cfg.enable_hierarchical_cache and (\n                cfg.hicache_storage_backend is not None\n                or cfg.hicache_write_policy != \"write_back\"\n            ):\n                logger.warning(\n                    \"Optimistic prefill only supports L2 hierarchical cache \"\n                    \"with write-back policy\"","sourceCodeStart":9556,"sourceCodeEnd":9592,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/server_args.py#L9556-L9592","documentation":"Raised by _handle_other_validations when --default-chat-template-kwargs was parsed but did not decode to a JSON object (dict). The value must be a JSON mapping of kwargs passed to the chat template renderer; arrays, strings, or scalars are rejected.","triggerScenarios":"Passing --default-chat-template-kwargs '[1,2]' or '\"text\"' or other non-object JSON; also when a config loader mis-parses the string into a non-dict.","commonSituations":"Forgetting braces around the JSON; quoting issues in shell causing partial parse; passing a template string instead of kwargs.","solutions":["Ensure the value is a JSON object: --default-chat-template-kwargs '{\"enable_thinking\": false}'","Verify shell quoting preserves the braces","If loading programmatically, json.loads the value and check isinstance(dict) before launch"],"exampleFix":"# before\n--default-chat-template-kwargs \"true\"\n# after\n--default-chat-template-kwargs '{\"enable_thinking\": false}'","handlingStrategy":"type-guard","validationCode":"import json\nif args.default_chat_template_kwargs is not None:\n    v = args.default_chat_template_kwargs\n    if isinstance(v, str):\n        v = json.loads(v)\n    assert isinstance(v, dict), 'default_chat_template_kwargs must be a JSON object'","typeGuard":"def is_valid_template_kwargs(v) -> bool:\n    import json\n    if isinstance(v, str):\n        try: v = json.loads(v)\n        except Exception: return False\n    return isinstance(v, dict)","tryCatchPattern":"except ValueError as e:\n    if 'default-chat-template-kwargs' in str(e):\n        fix quoting / re-pass as a JSON object","preventionTips":["Always wrap the value in single quotes with inner JSON braces","json.loads + isinstance(dict) check in any programmatic launcher"],"tags":["sglang","chat-template","json","server-args","validation"],"backgroundTag":"json-schema-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}