{"record":{"id":"aec23f52828359fb","repo":"microsoft/autogen","slug":"invalid-return-type-self-server-params-return-ty","errorCode":null,"errorMessage":"Invalid return type: {self.server_params.return_type}","messagePattern":"Invalid return type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/tools/http/_http_tool.py","lineNumber":244,"sourceCode":"            match self.server_params.method:\n                case \"GET\":\n                    response = await client.get(url, headers=self.server_params.headers, params=model_dump)\n                case \"PUT\":\n                    response = await client.put(url, headers=self.server_params.headers, json=model_dump)\n                case \"DELETE\":\n                    response = await client.delete(url, headers=self.server_params.headers, params=model_dump)\n                case \"PATCH\":\n                    response = await client.patch(url, headers=self.server_params.headers, json=model_dump)\n                case _:  # Default case POST\n                    response = await client.post(url, headers=self.server_params.headers, json=model_dump)\n\n        match self.server_params.return_type:\n            case \"text\":\n                return response.text\n            case \"json\":\n                return response.json()\n            case _:\n                raise ValueError(f\"Invalid return type: {self.server_params.return_type}\")\n","sourceCodeStart":226,"sourceCodeEnd":245,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/tools/http/_http_tool.py#L226-L245","documentation":"HttpTool.run executes the HTTP request and then switches on server_params.return_type, accepting only 'text' or 'json'; any other value falls through to ValueError('Invalid return type: ...'). The check happens after the request has already been sent, so a bad config surfaces late — the network call succeeds and then parsing fails.","triggerScenarios":"Constructing HttpToolServerParams with return_type set to something other than 'text'/'json' — e.g. 'string', 'raw', 'binary', 'JSON', or None — then calling tool.run(). The match statement hits the default branch only after the HTTP request completes.","commonSituations":"Guessing the return_type vocabulary ('string', 'str', 'body') instead of reading the enum; case mismatch like 'JSON'; copy-pasting a params dict from a different tool; passing None expecting auto-detection.","solutions":["Set return_type='text' or return_type='json' (lowercase) in HttpToolServerParams.","If you need a status code or headers, read them from the tool's structured output configuration rather than an unsupported return_type.","Add an assertion/guard right after constructing the params so misconfiguration fails before the request: assert params.return_type in {'text','json'}."],"exampleFix":"# before\nparams = HttpToolServerParams(\n    url=\"https://api.example.com/items\",\n    method=\"GET\",\n    return_type=\"string\",  # invalid\n)\n\n# after\nparams = HttpToolServerParams(\n    url=\"https://api.example.com/items\",\n    method=\"GET\",\n    return_type=\"text\",\n)","handlingStrategy":"validation","validationCode":"if params.return_type not in {\"text\", \"json\"}:\n    raise ValueError(f\"return_type must be 'text' or 'json', got {params.return_type!r}\")\ntool = HttpTool(params)","typeGuard":"def is_valid_return_type(rt: str) -> TypeGuard[str]:\n    return isinstance(rt, str) and rt in {\"text\", \"json\"}","tryCatchPattern":"try:\n    out = await tool.run(args, cancellation_token)\nexcept ValueError as e:\n    if \"Invalid return type\" in str(e):\n        # note: request already fired; fix config and retry\n        params.return_type = \"text\"\n    raise","preventionTips":["Assert the return_type vocabulary immediately after building HttpToolServerParams so it fails before any request is sent.","Centralize tool params construction in one factory with validated literals.","Document the allowed set ('text','json') next to every construction site."],"tags":["http","config","validation","rest"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}