sgl-project/sglang · error · DS32EncodingError
Invalid thinking_mode `{thinking_mode}`
Error message
Invalid thinking_mode `{thinking_mode}` What it means
DSv32 chat encoding rejects an unknown thinking_mode. render_message only supports 'chat' and 'thinking'; any other string (or a typo) raises DS32EncodingError before any rendering.
Source
Thrown at python/sglang/srt/entrypoints/openai/encoding_dsv32.py:168
def find_last_user_index(messages: List[Dict[str, Any]]) -> int:
last_user_index = -1
for idx in range(len(messages) - 1, -1, -1):
if messages[idx].get("role") in ["user", "developer"]:
last_user_index = idx
break
return last_user_index
def render_message(
index: int, messages: List[Dict[str, Any]], thinking_mode: str
) -> str:
if not (0 <= index < len(messages)):
raise DS32EncodingError(
f"Index {index} out of range for messages list of length {len(messages)}"
)
if thinking_mode not in ["chat", "thinking"]:
raise DS32EncodingError(f"Invalid thinking_mode `{thinking_mode}`")
prompt = ""
msg = messages[index]
last_user_idx = find_last_user_index(messages)
role = msg.get("role")
content = msg.get("content")
tools = msg.get("tools")
response_format = msg.get("response_format")
tool_calls = msg.get("tool_calls")
reasoning_content = msg.get("reasoning_content")
if tools:
tools = tools_from_openai_format(tools)
if tool_calls:
tool_calls = tool_calls_from_openai_format(tool_calls)
if role == "system":View on GitHub (pinned to 0132848349)
Solutions
- Set thinking_mode to exactly 'chat' or 'thinking' (lowercase).
- Check where thinking_mode is derived (server args / chat completion request) and normalize with .lower() before calling encode_messages.
- Upgrade sglang if a newer mode name was introduced and your copy is stale.
Example fix
# before encode_messages(msgs, thinking_mode='Thinking') # after encode_messages(msgs, thinking_mode='thinking')
Defensive patterns
Strategy: validation
Validate before calling
assert thinking_mode in ('chat','thinking'), f"bad thinking_mode: {thinking_mode!r}" Type guard
def is_valid_thinking_mode(m: str) -> bool:
return isinstance(m, str) and m in ('chat','thinking') Prevention
- Normalize thinking_mode with .lower() before calling encode_messages.
- Centralize mode names as constants.
When it happens
Trigger: Calling encode_messages/render_message for the deepseek-v3.2 chat template with thinking_mode set to something other than 'chat' or 'thinking' (e.g. 'Think', 'auto', None passed as string, or a future mode name).
Common situations: Passing server args like --reasoning-quotes or a chat template flag that maps to a thinking_mode string not in the allowlist; case mismatch ('Thinking'); version upgrade that renamed modes.
Related errors
- No tool calls but found tool output
- ThinkingMode: {thinking_mode}, invalid message without reaso
- Unknown role: {role}
- Invalid content format: {content_format}
- --default-chat-template-kwargs must decode to a JSON object
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/7f18b77a311d4fe2.
Report an issue: GitHub.