{"record":{"id":"1742d69c35158cfd","repo":"sgl-project/sglang","slug":"function-tools-must-include-a-name","errorCode":null,"errorMessage":"Function tools must include a name.","messagePattern":"Function tools must include a name\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/entrypoints/openai/protocol.py","lineNumber":1566,"sourceCode":"    \"tool_search\",\n]\n\n\nclass ResponseTool(BaseModel):\n    \"\"\"Tool definition for responses.\"\"\"\n\n    type: RESPONSE_TOOL_TYPES = Field(description=\"Type of tool to enable\")\n    name: Optional[str] = None\n    description: Optional[str] = None\n    parameters: Optional[Dict[str, Any]] = None\n    strict: bool = False\n    # Inner schemas for ``namespace`` tools.\n    tools: Optional[List[Dict[str, Any]]] = None\n\n    @model_validator(mode=\"after\")\n    def validate_function_tool(self) -> ResponseTool:\n        if self.type == \"function\" and not self.name:\n            raise ValueError(\"Function tools must include a name.\")\n        return self\n\n\nResponseInputOutputItem: TypeAlias = Union[\n    ResponseInputItemParam,\n    \"ResponseReasoningItem\",\n    ResponseFunctionToolCall,\n]\n\n\nclass ResponsesRequest(BaseModel):\n    \"\"\"Request body for v1/responses endpoint.\"\"\"\n\n    # Core OpenAI API fields (ordered by official documentation)\n    background: Optional[bool] = False\n    include: Optional[\n        List[\n            Literal[","sourceCodeStart":1548,"sourceCodeEnd":1584,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/entrypoints/openai/protocol.py#L1548-L1584","documentation":"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.","triggerScenarios":"POST /v1/responses with tools=[{\"type\": \"function\"}] where name is missing or empty (older nested {'type':'function','function':{...}} shapes without a name also fail).","commonSituations":"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.","solutions":["Use the flat Responses-API tool shape: {\"type\":\"function\",\"name\":\"get_weather\",\"parameters\":{...}}","If porting from chat completions, hoist function.name and function.parameters to the top level"],"exampleFix":"// before\n{\"tools\": [{\"type\": \"function\", \"function\": {\"name\": \"f\"}}]}\n// after\n{\"tools\": [{\"type\": \"function\", \"name\": \"f\", \"parameters\": {...}}]}","handlingStrategy":"type-guard","validationCode":"for t in tools:\n    if t.get(\"type\") == \"function\":\n        assert t.get(\"name\"), \"function tool needs a name\"","typeGuard":"def valid_response_tool(t): return t.get('type') != 'function' or bool(t.get('name'))","tryCatchPattern":null,"preventionTips":["Use the flat Responses-API tool schema, not nested chat-completions shape","Add a unit test over your tool list"],"tags":["responses-api","tool-calling","validation","sglang"],"backgroundTag":"schema-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}