sgl-project/sglang · error · ValueError

Unknown type: {type(other)}

Error message

Unknown type: {type(other)}

What it means

Raised by the SGL program interpreter's _execute when submit()/`+=` receives an object that is not one of the recognized SGL primitives (str, SglGen, SglSelect, SglImage, SglConcateAndAppend, SglSeparateReasoning, etc.). It is a dispatch failure: the value type is unsupported in a program statement.

Source

Thrown at python/sglang/lang/interpreter.py:503

            self._execute_variable(other)
        elif isinstance(other, SglVarScopeBegin):
            self._execute_var_scope_begin(other)
        elif isinstance(other, SglVarScopeEnd):
            self._execute_var_scope_end(other)
        elif isinstance(other, SglCommitLazy):
            self._execute_commit_lazy_operations(other)
        elif isinstance(other, SglConcateAndAppend):
            if (
                global_config.enable_parallel_encoding
                and self.backend.support_concate_and_append
            ):
                self._execute_concatenate_and_append_kv_cache(other)
            else:
                self._execute_concatenate_and_append_text(other)
        elif isinstance(other, SglSeparateReasoning):
            self._execute_separate_reasoning(other)
        else:
            raise ValueError(f"Unknown type: {type(other)}")

    def _execute_fill(self, value: str, prefix=False):
        value = str(value)

        if (
            self.cur_role == "assistant"
            and self.num_api_spec_tokens is not None
            and self.backend.is_chat_model
            and not prefix
        ):
            self.backend.spec_fill(value)
            return

        if self.speculated_text.startswith(value):
            self.speculated_text = self.speculated_text[len(value) :]
        else:
            self.speculated_text = ""

View on GitHub (pinned to 0132848349)

Solutions

  1. Convert the value to a string or use the appropriate Sgl* class (SglGen for generation, SglSelect for choices, SglImage for images)
  2. Upgrade/downgrade sglang so the primitive class matches between the API that built the object and the interpreter executing it
  3. Check the object is not None (None also falls through to this branch)

Example fix

# before
state += {"role": "user", "text": "hi"}   # dict is not supported
# after
state += "hi"                            # plain text
# or
state += SglGen("hi", sampling_params={...})
Defensive patterns

Strategy: type-guard

Validate before calling

from sglang.lang.ir import SglGen, SglSelect, SglImage
ALLOWED = (str, SglGen, SglSelect, SglImage)
def appendable(v) -> bool:
    return isinstance(v, ALLOWED) and v is not None

Type guard

def is_sgl_primitive(v) -> bool:
    from sglang.lang.ir import SglGen, SglSelect, SglImage
    return isinstance(v, (str, SglGen, SglSelect, SglImage))

Try / catch

try:
    state += value
except ValueError as e:
    if "Unknown type" in str(e):
        state += str(value)  # coerce fallback
    else:
        raise

Prevention

When it happens

Trigger: Doing `state += obj` or state.stream_executor.submit(obj) with an arbitrary Python object (dict, int, custom class) instead of a string or Sgl primitive; passing a primitive added in a newer sglang version to an older interpreter.

Common situations: See trigger scenarios.

Related errors


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