sgl-project/sglang · error · ValueError

Unknown separator style: {template['sep_style']}

Error message

Unknown separator style: {template['sep_style']}

What it means

When loading a JSON chat template file, the 'sep_style' string is used as a key into the SeparatorStyle enum. An unknown key raises this ValueError. Note template['sep_style'] is accessed directly, so a missing key surfaces as a plain KeyError instead.

Source

Thrown at python/sglang/srt/parser/template_manager.py:291

        self._jinja_template_content_format = detect_jinja_template_content_format(
            chat_template
        )
        logger.info(
            f"Detected user specified Jinja chat template with content format: {self._jinja_template_content_format}"
        )

    def _load_json_chat_template(self, template_path: str) -> None:
        """Load a JSON chat template file."""
        assert template_path.endswith(
            ".json"
        ), "unrecognized format of chat template file"

        with open(template_path, "r") as filep:
            template = json.load(filep)
            try:
                sep_style = SeparatorStyle[template["sep_style"]]
            except KeyError:
                raise ValueError(
                    f"Unknown separator style: {template['sep_style']}"
                ) from None

            register_conv_template(
                Conversation(
                    name=template["name"],
                    system_template=template["system"] + "\n{system_message}",
                    system_message=template.get("system_message", ""),
                    roles=(template["user"], template["assistant"]),
                    sep_style=sep_style,
                    sep=template.get("sep", "\n"),
                    stop_str=template["stop_str"],
                ),
                override=True,
            )
        self._chat_template_name = template["name"]

    def _load_json_completion_template(self, template_path: str) -> None:

View on GitHub (pinned to 0132848349)

Solutions

  1. Use an exact SeparatorStyle enum member name (inspect the enum in sglang/srt/conversation.py)
  2. If porting from fastchat, map legacy string styles to the enum names
  3. Prefer .jinja templates over JSON conv templates for new setups

Example fix

// before
{"name": "mytmpl", "sep_style": "single", ...}
// after
{"name": "mytmpl", "sep_style": "SeparatorStyle.ADD_COLON_SINGLE", ...}  // or exact enum member name e.g. "ADD_COLON_SINGLE"
Defensive patterns

Strategy: validation

Validate before calling

import json
from sglang.srt.conversation import SeparatorStyle

tpl = json.load(open(path))
assert tpl["sep_style"] in SeparatorStyle.__members__, f"bad sep_style {tpl['sep_style']}; valid: {list(SeparatorStyle.__members__)}"

Type guard

def has_valid_sep_style(tpl: dict) -> TypeGuard[dict]:
    from sglang.srt.conversation import SeparatorStyle
    return isinstance(tpl.get("sep_style"), str) and tpl["sep_style"] in SeparatorStyle.__members__

Try / catch

try:
    tm._load_explicit_chat_template(tokenizer_manager, path)
except ValueError as e:
    if "Unknown separator style" in str(e):
        fix_sep_style_enum_name(path)  # edit JSON, retry
    else:
        raise

Prevention

When it happens

Trigger: A custom JSON chat template containing "sep_style": "ADD_COLON_SINGLE" (or any string not a SeparatorStyle member) being loaded via _load_explicit_chat_template.

Common situations: Porting conv templates from fastchat versions where sep_style names differ (e.g. plain string styles like 'single' vs enum names), or hand-edited JSON with a typo.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/a71f8b61c4fbbc89. Report an issue: GitHub.