{"record":{"id":"bb6a5ca96d60c7de","repo":"BerriAI/litellm","slug":"unexpected-response-type-type-raw-response","errorCode":null,"errorMessage":"Unexpected response type: {type(raw_response)}","messagePattern":"Unexpected response type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/completion_extras/litellm_responses_transformation/transformation.py","lineNumber":742,"sourceCode":"        self,\n        model: str,\n        raw_response: \"BaseModel\",\n        model_response: \"ModelResponse\",\n        logging_obj: \"LiteLLMLoggingObj\",\n        request_data: dict,\n        messages: list[\"AllMessageValues\"],\n        optional_params: dict,\n        litellm_params: dict,\n        encoding: object,\n        api_key: str | None = None,\n        json_mode: bool | None = None,\n    ) -> \"ModelResponse\":\n        \"\"\"Transform Responses API response to chat completion response\"\"\"\n        from litellm.responses.utils import ResponseAPILoggingUtils\n        from litellm.types.llms.openai import ResponsesAPIResponse\n\n        if not isinstance(raw_response, ResponsesAPIResponse):\n            raise ValueError(f\"Unexpected response type: {type(raw_response)}\")\n\n        if raw_response.error is not None:\n            raise ValueError(f\"Error in response: {raw_response.error}\")\n\n        output_items = raw_response.output\n        if len(output_items) == 0:\n            recovered_output_items: Final = self._recover_output_items_from_logging(logging_obj)\n            if recovered_output_items:\n                output_items = cast(Any, recovered_output_items)\n                raw_response.output = cast(Any, recovered_output_items)\n                verbose_logger.warning(\n                    \"Recovered empty Responses API output from raw SSE for model=%s\",\n                    model,\n                )\n\n        # Convert response output to choices using the static helper\n        choices: Final = self._convert_response_output_to_choices(\n            output_items=output_items,","sourceCodeStart":724,"sourceCodeEnd":760,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/completion_extras/litellm_responses_transformation/transformation.py#L724-L760","documentation":"transform_response raises this when the object passed as raw_response is not a litellm ResponsesAPIResponse. This method is the Responses→chat-completions converter used by the bridge; feeding it a raw httpx.Response, a plain dict, or an OpenAI SDK response object instead of the parsed ResponsesAPIResponse trips this guard.","triggerScenarios":"Calling LiteLLMResponsesTransformationHandler.transform_response (or the bridge) with the unparsed HTTP body or an SDK object; a provider adapter returning the raw JSON dict instead of validating it into ResponsesAPIResponse first.","commonSituations":"Custom provider integrations that skip the schema validation step; tests passing fixtures as dicts; refactors that changed what the transport returns.","solutions":["Parse the payload first: ResponsesAPIResponse(**json_body) before calling transform_response","Let litellm's own provider adapter do the parsing — do not call transform_response with transport-level objects","In tests, construct fixtures as ResponsesAPIResponse instances or validated dicts"],"exampleFix":"# before\nresp = await client.post(url, json=payload)\nmodel_resp = handler.transform_response(resp.json(), ...)  # raw dict\n\n# after\nfrom litellm.types.llms.openai import ResponsesAPIResponse\nparsed = ResponsesAPIResponse(**resp.json())\nmodel_resp = handler.transform_response(parsed, ...)","handlingStrategy":"type-guard","validationCode":"from litellm.types.llms.openai import ResponsesAPIResponse\n\ndef is_parsed_responses_payload(raw) -> bool:\n    return isinstance(raw, ResponsesAPIResponse)","typeGuard":"from litellm.types.llms.openai import ResponsesAPIResponse\n\ndef is_responses_api_response(v) -> bool:\n    return isinstance(v, ResponsesAPIResponse)","tryCatchPattern":null,"preventionTips":["Always run ResponsesAPIResponse(**body) before transform_response","Never hand transport-level objects (httpx.Response, raw dicts) to transformers"],"tags":["transformation","responses-api","type-validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}