{"record":{"id":"044e5017e9da4c84","repo":"sgl-project/sglang","slug":"chat-template-chat-template-arg-is-not-a-built-i","errorCode":null,"errorMessage":"Chat template {chat_template_arg} is not a built-in template name or a valid chat template file path.","messagePattern":"Chat template (.+?) is not a built-in template name or a valid chat template file path\\.","errorType":"error_code","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/parser/template_manager.py","lineNumber":197,"sourceCode":"            if self._suggested_reasoning_parser:\n                parts.append(f\"reasoning_parser={self._suggested_reasoning_parser}\")\n            if self._suggested_tool_call_parser:\n                parts.append(f\"tool_call_parser={self._suggested_tool_call_parser}\")\n            if parts:\n                logger.info(f\"Auto-detected template features: {', '.join(parts)}\")\n\n    def _load_explicit_chat_template(\n        self, tokenizer_manager: TokenizerManager, chat_template_arg: str\n    ) -> None:\n        \"\"\"Load explicitly specified chat template.\"\"\"\n        logger.info(f\"Loading chat template from argument: {chat_template_arg}\")\n\n        if chat_template_exists(chat_template_arg):\n            self._chat_template_name = chat_template_arg\n            return\n\n        if not os.path.exists(chat_template_arg):\n            raise RuntimeError(\n                f\"Chat template {chat_template_arg} is not a built-in template name \"\n                \"or a valid chat template file path.\"\n            )\n\n        if chat_template_arg.endswith(\".jinja\"):\n            self._load_jinja_template(tokenizer_manager, chat_template_arg)\n        else:\n            self._load_json_chat_template(chat_template_arg)\n\n    def guess_chat_template_from_model_path(self, model_path: str) -> None:\n        \"\"\"\n        Infer chat template name from model path.\n\n        Args:\n            model_path: Path to the model\n        \"\"\"\n        template_name = get_conv_template_by_model_path(model_path)\n        if template_name is not None:","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/parser/template_manager.py#L179-L215","documentation":"When an explicit --chat-template argument is given, TemplateManager first tries builtin template names, then treats it as a file path. If neither matches, this RuntimeError reports the value is neither a builtin name nor an existing file.","triggerScenarios":"Launching the server with --chat-template my_template (not a registered builtin) where ./my_template also doesn't exist on disk; or a path with a typo/relative to wrong working directory.","commonSituations":"Typos in builtin template names, moved/renamed template files, relative paths resolved from a different CWD (e.g. running under systemd or Docker), or missing file in the container image.","solutions":["Verify the file exists with an absolute path: ls -l /full/path/to/template.jinja","Or use an exact builtin template name (check the registered names in sglang)","If in a container, ensure the template file is mounted/copied into the image"],"exampleFix":"# before\npython -m sglang.launch_server --chat-template mytmpl\n# after\npython -m sglang.launch_server --chat-template /app/templates/mytmpl.jinja","handlingStrategy":"validation","validationCode":"import os\nok = chat_template_exists(arg) or os.path.isfile(os.path.abspath(arg))\nif not ok:\n    raise FileNotFoundError(f\"template {arg!r} not found; use builtin name or absolute path\")","typeGuard":"def is_loadable_template(arg: str) -> TypeGuard[str]:\n    import os\n    from sglang.srt.parser.template_manager import chat_template_exists\n    return chat_template_exists(arg) or os.path.isfile(arg)","tryCatchPattern":"try:\n    tm.load_chat_template(chat_template_arg, tokenizer_manager)\nexcept RuntimeError as e:\n    if \"not a built-in template name\" in str(e):\n        sys.exit(f\"fix --chat-template path: {chat_template_arg}\")\n    raise","preventionTips":["Use absolute paths for template files","Verify builtin names against the registered list before launch","Mount template files explicitly when containerizing"],"tags":["chat-template","template-manager","file-not-found","server-args"],"backgroundTag":"chat-template-not-found","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}