sgl-project/sglang · error · ValueError
Invalid style: {self.sep_style}
Error message
Invalid style: {self.sep_style} What it means
SeparatorStyle.get_prompt() serializes a conversation according to self.sep_style, and only a fixed set of SeparatorStyle enum members have rendering branches. If a Conversation was constructed with an unrecognized or newly added SeparatorStyle value, the final else branch raises 'Invalid style'.
Source
Thrown at python/sglang/srt/parser/conversation.py:413
else:
ret += message + self.sep
else:
ret += role + ": " # must be end with a space
return ret
elif self.sep_style == SeparatorStyle.UNLIMITED_OCR:
seps = [self.sep, self.sep2]
if system_prompt == "" or system_prompt is None:
ret = ""
else:
ret = system_prompt + seps[0]
for i, (role, message) in enumerate(self.messages):
if message:
ret += role + message + seps[i % 2]
else:
ret += role
return ret
else:
raise ValueError(f"Invalid style: {self.sep_style}")
def set_system_message(self, system_message: str):
"""Set the system message."""
self.system_message = system_message
def append_message(self, role: str, message: str):
"""Append a new message."""
self.messages.append([role, message])
def append_image(self, image: str, detail: Literal["auto", "low", "high"]):
"""Append a new image."""
self.image_data.append(ImageData(url=image, detail=detail))
def append_video(self, video: str, preprocess_kwargs: Optional[Dict] = None):
"""Append a new video."""
if preprocess_kwargs:
self.video_data.append(
VideoData(video, preprocess_kwargs=preprocess_kwargs)View on GitHub (pinned to 0132848349)
Solutions
- Add a rendering branch in get_prompt() for the missing SeparatorStyle member
- Verify the sep_style passed to the Conversation constructor is one of the styles handled in get_prompt()
- Use an existing style (e.g. SeparatorStyle.PLAIN) instead of a custom value
Example fix
# before conv = Conversation(name="x", sep_style=SeparatorStyle(99), ...) # after conv = Conversation(name="x", sep_style=SeparatorStyle.PLAIN, ...) # or add to get_prompt(): # elif self.sep_style == SeparatorStyle.MY_STYLE: ...
Defensive patterns
Strategy: validation
Validate before calling
from sglang.srt.parser.conversation import SeparatorStyle assert conv.sep_style in SeparatorStyle, "unknown sep_style" # plus ensure get_prompt handles it
Prevention
- When adding a SeparatorStyle enum member, add the get_prompt branch in the same commit
- Add a unit test per style that calls get_prompt()
When it happens
Trigger: Constructing a Conversation with sep_style set to a SeparatorStyle enum member (or raw int) that has no branch in get_prompt(), e.g. a style added to the enum but not implemented in get_prompt, or a custom/out-of-range integer passed as sep_style.
Common situations: Porting a new chat template into SGLang's conversation.py and registering the enum value without adding a rendering branch; deserializing a Conversation from stale config after an upgrade shifted enum values.
Related errors
- Invalid thinking_mode `{thinking_mode}`
- Unknown role: {role}
- Assistant tool call function.arguments must be valid JSON.
- {template_error}
- {template_error}{suffix}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/73407b0d5a0663e7.
Report an issue: GitHub.