sgl-project/sglang · error · ValueError

Unknown output type: {type(output)}

Error message

Unknown output type: {type(output)}

What it means

parse_response_output raises when a ResponseOutputItem is neither a ResponseOutputMessage nor a ResponseFunctionToolCall — the only two output shapes it knows how to convert into harmony Messages. Any other subclass (or a duck-typed lookalike) hits the else branch.

Source

Thrown at python/sglang/srt/entrypoints/harmony_utils.py:216

    else:
        raise ValueError(f"Unknown input type: {response_msg['type']}")
    return msg


def parse_response_output(output: ResponseOutputItem) -> Message:
    if isinstance(output, ResponseOutputMessage):
        role = output.role
        contents = [TextContent(text=c.text) for c in output.content]
        msg = Message.from_role_and_contents(role, contents)
        return msg
    elif isinstance(output, ResponseFunctionToolCall):
        msg = Message.from_role_and_content(Role.ASSISTANT, output.arguments)
        msg = msg.with_channel("commentary")
        msg = msg.with_recipient(output.name)
        msg = msg.with_content_type("json")
        return msg
    else:
        raise ValueError(f"Unknown output type: {type(output)}")


def parse_chat_input(chat_msg) -> Message:
    role = chat_msg.role
    content = chat_msg.content
    if isinstance(content, str):
        contents = [TextContent(text=content)]
    else:
        # TODO: Support refusal.
        contents = [TextContent(text=c.text) for c in content]
    msg = Message.from_role_and_contents(role, contents)
    return msg


def render_for_completion(messages: list[Message]) -> list[int]:
    conversation = Conversation.from_messages(messages)
    token_ids = get_encoding().render_conversation_for_completion(
        conversation, Role.ASSISTANT

View on GitHub (pinned to 0132848349)

Solutions

  1. Handle/convert the extra output item types before calling parse_response_output
  2. Filter items to ResponseOutputMessage and ResponseFunctionToolCall instances
  3. Upgrade sglang so its parser covers the item types you emit

Example fix

# before
msgs = [parse_response_output(o) for o in outputs]
# after
msgs = [parse_response_output(o) for o in outputs
        if isinstance(o, (ResponseOutputMessage, ResponseFunctionToolCall))]
Defensive patterns

Strategy: type-guard

Validate before calling

from sglang.srt.entrypoints.openai.protocol import ResponseOutputMessage, ResponseFunctionToolCall
filtered = [o for o in outputs if isinstance(o, (ResponseOutputMessage, ResponseFunctionToolCall))]

Type guard

def is_parseable_output(o) -> bool:
    from sglang.srt.entrypoints.openai.protocol import ResponseOutputMessage, ResponseFunctionToolCall
    return isinstance(o, (ResponseOutputMessage, ResponseFunctionToolCall))

Try / catch

try:
    msg = parse_response_output(o)
except ValueError as e:
    if "Unknown output type" in str(e):
        return None
    raise

Prevention

When it happens

Trigger: Passing a ResponseReasoningItem, ResponseFunctionWebSearch, or any new/custom ResponseOutputItem subclass into parse_response_output.

Common situations: Extending the Responses API output model with new item kinds without updating the parser; feeding recorded outputs from a newer server version into an older sglang client library.

Related errors


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