sgl-project/sglang · error · ValueError

Function tools must include a name.

Error message

Function tools must include a name.

What it means

ResponseTool.validate_function_tool requires that a tool of type 'function' has a non-empty name. The Responses-API tool object must carry the function name for the model to call it.

Source

Thrown at python/sglang/srt/entrypoints/openai/protocol.py:1566

    "tool_search",
]


class ResponseTool(BaseModel):
    """Tool definition for responses."""

    type: RESPONSE_TOOL_TYPES = Field(description="Type of tool to enable")
    name: Optional[str] = None
    description: Optional[str] = None
    parameters: Optional[Dict[str, Any]] = None
    strict: bool = False
    # Inner schemas for ``namespace`` tools.
    tools: Optional[List[Dict[str, Any]]] = None

    @model_validator(mode="after")
    def validate_function_tool(self) -> ResponseTool:
        if self.type == "function" and not self.name:
            raise ValueError("Function tools must include a name.")
        return self


ResponseInputOutputItem: TypeAlias = Union[
    ResponseInputItemParam,
    "ResponseReasoningItem",
    ResponseFunctionToolCall,
]


class ResponsesRequest(BaseModel):
    """Request body for v1/responses endpoint."""

    # Core OpenAI API fields (ordered by official documentation)
    background: Optional[bool] = False
    include: Optional[
        List[
            Literal[

View on GitHub (pinned to 0132848349)

Solutions

  1. Use the flat Responses-API tool shape: {"type":"function","name":"get_weather","parameters":{...}}
  2. If porting from chat completions, hoist function.name and function.parameters to the top level

Example fix

// before
{"tools": [{"type": "function", "function": {"name": "f"}}]}
// after
{"tools": [{"type": "function", "name": "f", "parameters": {...}}]}
Defensive patterns

Strategy: type-guard

Validate before calling

for t in tools:
    if t.get("type") == "function":
        assert t.get("name"), "function tool needs a name"

Type guard

def valid_response_tool(t): return t.get('type') != 'function' or bool(t.get('name'))

Prevention

When it happens

Trigger: POST /v1/responses with tools=[{"type": "function"}] where name is missing or empty (older nested {'type':'function','function':{...}} shapes without a name also fail).

Common situations: Using the OpenAI Chat-Completions nested tool schema ({'type':'function','function':{...}}) on the Responses API which expects a flat schema; tools generated from JSON schemas that lack a top-level name.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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