sgl-project/sglang · error · NotImplementedError
Unknown role: {role}
Error message
Unknown role: {role} What it means
DSv4 render_message reached the final else branch: the message role matched none of the supported roles (user/developer/assistant/latest_reminder/tool handled earlier).
Source
Thrown at python/sglang/srt/entrypoints/openai/encoding_dsv4.py:438
thinking_template.format(reasoning_content=rc) + thinking_end_token
)
else:
thinking_part = ""
if wo_eos:
prompt += assistant_msg_wo_eos_template.format(
reasoning=thinking_part,
content=summary_content,
tool_calls=tc_content,
)
else:
prompt += assistant_msg_template.format(
reasoning=thinking_part,
content=summary_content,
tool_calls=tc_content,
)
else:
raise NotImplementedError(f"Unknown role: {role}")
# Append transition tokens based on what follows
if index + 1 < len(messages) and messages[index + 1].get("role") not in [
"assistant",
"latest_reminder",
]:
return prompt
task = messages[index].get("task")
if task is not None:
# Task special token for internal classification tasks
assert (
task in VALID_TASKS
), f"Invalid task: '{task}'. Valid tasks are: {list(VALID_TASKS)}"
task_sp_token = DS_TASK_SP_TOKENS[task]
if task != "action":
# Non-action tasks: append task sp token directly after the messageView on GitHub (pinned to 0132848349)
Solutions
- Check msg['role'] spelling and use a supported role.
- Map legacy roles: 'system'->'developer', 'function'->tool handling via merge_tool_messages.
- Log roles before sending to catch bad values early.
Example fix
# before
{"role":"system","content":"You are..."}
# after
{"role":"developer","content":"You are..."} Defensive patterns
Strategy: type-guard
Validate before calling
ALLOWED={'user','developer','assistant','latest_reminder'}
assert all(m['role'] in ALLOWED for m in messages) Type guard
def is_dsv4_role(r): return r in {'user','developer','assistant','latest_reminder'} Prevention
- Map system->developer for DSv4.
- Check supported roles per encoder version.
When it happens
Trigger: A message with an unrecognized role such as 'system' in DSv4 (if unsupported), 'function', or a typo like 'asistant'.
Common situations: Role typos; using legacy roles; roles supported by other templates but not DSv4.
Related errors
- `task` requires at least one message with role='user' or 'de
- DSV4 draft state transfer expects SWA-only NextN layers
- DSV4 target and draft pools must use the same unified-KV mod
- DSV4 target and draft pools must share SWA ring geometry: ta
- DSV4 target and draft pools must share the SWA index mapping
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/9954fbfa8f8b3bd5.
Report an issue: GitHub.