{"record":{"id":"7f18b77a311d4fe2","repo":"sgl-project/sglang","slug":"invalid-thinking-mode-thinking-mode","errorCode":null,"errorMessage":"Invalid thinking_mode `{thinking_mode}`","messagePattern":"Invalid thinking_mode `(.+?)`","errorType":"exception","errorClass":"DS32EncodingError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/entrypoints/openai/encoding_dsv32.py","lineNumber":168,"sourceCode":"\ndef find_last_user_index(messages: List[Dict[str, Any]]) -> int:\n    last_user_index = -1\n    for idx in range(len(messages) - 1, -1, -1):\n        if messages[idx].get(\"role\") in [\"user\", \"developer\"]:\n            last_user_index = idx\n            break\n    return last_user_index\n\n\ndef render_message(\n    index: int, messages: List[Dict[str, Any]], thinking_mode: str\n) -> str:\n    if not (0 <= index < len(messages)):\n        raise DS32EncodingError(\n            f\"Index {index} out of range for messages list of length {len(messages)}\"\n        )\n    if thinking_mode not in [\"chat\", \"thinking\"]:\n        raise DS32EncodingError(f\"Invalid thinking_mode `{thinking_mode}`\")\n\n    prompt = \"\"\n    msg = messages[index]\n    last_user_idx = find_last_user_index(messages)\n\n    role = msg.get(\"role\")\n    content = msg.get(\"content\")\n    tools = msg.get(\"tools\")\n    response_format = msg.get(\"response_format\")\n    tool_calls = msg.get(\"tool_calls\")\n    reasoning_content = msg.get(\"reasoning_content\")\n\n    if tools:\n        tools = tools_from_openai_format(tools)\n    if tool_calls:\n        tool_calls = tool_calls_from_openai_format(tool_calls)\n\n    if role == \"system\":","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/entrypoints/openai/encoding_dsv32.py#L150-L186","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"# before\nencode_messages(msgs, thinking_mode='Thinking')\n# after\nencode_messages(msgs, thinking_mode='thinking')","handlingStrategy":"validation","validationCode":"assert thinking_mode in ('chat','thinking'), f\"bad thinking_mode: {thinking_mode!r}\"","typeGuard":"def is_valid_thinking_mode(m: str) -> bool:\n    return isinstance(m, str) and m in ('chat','thinking')","tryCatchPattern":null,"preventionTips":["Normalize thinking_mode with .lower() before calling encode_messages.","Centralize mode names as constants."],"tags":["deepseek","chat-template","thinking-mode","validation"],"backgroundTag":"invalid-enum-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}