sgl-project/sglang · error · TypeError

assistant reasoning_content must be a string for Inkling ren

Error message

assistant reasoning_content must be a string for Inkling rendering

What it means

Inkling rendering supports assistant reasoning_content only as a string (typically produced by the model itself). If a truthy non-string value (dict, list, number) is passed, it raises TypeError.

Source

Thrown at python/sglang/srt/parser/inkling_renderer.py:130

                if kind == "thinking":
                    raise ValueError("Inkling thinking parts require role='assistant'")
                _append_message(
                    input_ids,
                    tokenizer,
                    "tool",
                    kind,
                    text,
                    author_name=tool_name,
                )
            continue

        parts = list(_iter_render_parts(message.get("content", "")))
        turn_start = len(input_ids)
        if role == "assistant":
            reasoning_content = message.get("reasoning_content")
            if reasoning_content:
                if not isinstance(reasoning_content, str):
                    raise TypeError(
                        "assistant reasoning_content must be a string for Inkling rendering"
                    )
                if any(kind == "thinking" for kind, _ in parts):
                    raise ValueError(
                        "assistant message cannot mix reasoning_content with ordered thinking parts"
                    )
                _append_message(
                    input_ids,
                    tokenizer,
                    "assistant",
                    "thinking",
                    reasoning_content,
                )

        for kind, text in parts:
            if kind == "thinking" and role != "assistant":
                raise ValueError("Inkling thinking parts require role='assistant'")
            _append_message(input_ids, tokenizer, role, kind, text)

View on GitHub (pinned to 0132848349)

Solutions

  1. Serialize reasoning_content to a single string (e.g. json.dumps or '\n'.join) before sending
  2. Omit reasoning_content from replayed history if the template allows

Example fix

# before
msg["reasoning_content"] = ["step 1", "step 2"]
# after
msg["reasoning_content"] = "\n".join(["step 1", "step 2"])
Defensive patterns

Strategy: type-guard

Validate before calling

for m in messages:
    rc = m.get("reasoning_content")
    if rc is not None: assert isinstance(rc, str), type(rc)

Type guard

def reasoning_ok(m):
    rc = m.get("reasoning_content")
    return rc is None or isinstance(rc, str)

Prevention

When it happens

Trigger: Passing message={"role":"assistant","reasoning_content":["step1"], ...} or reasoning_content={"text": "..."} to a chat request handled by the Inkling renderer.

Common situations: Clients that store reasoning as structured traces (lists of steps or JSON objects) and echo them back in multi-turn history.

Related errors


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