sgl-project/sglang · error · TypeError

Inkling reasoning_effort must be a number

Error message

Inkling reasoning_effort must be a number

What it means

The Inkling effort directive formats reasoning_effort as a number; passing a bool, string, None, or other non-numeric type raises TypeError (bool is explicitly rejected even though it is an int subclass).

Source

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

            text = part.get("thinking")
            if text is None:
                text = part.get("text", "")
            if not isinstance(text, str):
                raise TypeError("Inkling thinking part payload must be a string")
            yield ("thinking", text)
        elif ptype in _IMAGE_PART_TYPES:
            yield ("image", "")
        elif ptype in _AUDIO_PART_TYPES:
            yield ("audio", "")
        else:
            raise ValueError(f"unsupported content part type: {ptype!r}")


def _format_reasoning_effort(reasoning_effort: float) -> str:
    if isinstance(reasoning_effort, bool) or not isinstance(
        reasoning_effort, (int, float)
    ):
        raise TypeError("Inkling reasoning_effort must be a number")
    value = float(reasoning_effort)
    if not math.isfinite(value) or not 0.0 <= value <= 0.99:
        raise ValueError("Inkling reasoning_effort must be finite and in [0.0, 0.99]")
    return f"{round(value, 2):g}"


def _expect_role(message: Mapping[str, Any]) -> str:
    role = message.get("role")
    if role not in ROLE_MESSAGE_TOKENS:
        raise ValueError(
            f"unsupported Inkling message role {role!r}; expected one of {sorted(ROLE_MESSAGE_TOKENS)}"
        )
    return str(role)


def _as_mapping(value: Any) -> Mapping[str, Any]:
    if isinstance(value, Mapping):
        return value

View on GitHub (pinned to 0132848349)

Solutions

  1. Pass a numeric reasoning_effort, e.g. 0.8 instead of "high"
  2. Map string levels yourself: {"low":0.2,"medium":0.5,"high":0.8}

Example fix

# before
reasoning_effort="high"
# after
reasoning_effort=0.8
Defensive patterns

Strategy: type-guard

Validate before calling

effort = kwargs.get("reasoning_effort")
if effort is not None:
    assert isinstance(effort, (int, float)) and not isinstance(effort, bool), type(effort)

Type guard

def effort_ok(e): return e is None or (isinstance(e, (int, float)) and not isinstance(e, bool))

Prevention

When it happens

Trigger: Calling chat with extra_body/reasoning_effort="high" (a string, as some APIs accept) or reasoning_effort=True.

Common situations: OpenAI's API accepts string values like 'high'/'medium'/'low'; clients reuse those strings where this renderer expects a float in [0, 0.99].

Related errors


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