{"record":{"id":"d487fad2666b3547","repo":"BerriAI/litellm","slug":"unable-to-parse-response-original-response-chun","errorCode":null,"errorMessage":"Unable to parse response. Original response: {chunk}","messagePattern":"Unable to parse response\\. Original response: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/streaming_handler.py","lineNumber":540,"sourceCode":"                \"finish_reason\": finish_reason,\n            }\n        except Exception as e:\n            raise e\n\n    def handle_ai21_chunk(self, chunk):  # fake streaming\n        chunk = chunk.decode(\"utf-8\")\n        data_json: Final[_Ai21StreamData] = json.loads(chunk)\n        try:\n            text: Final = data_json[\"completions\"][0][\"data\"][\"text\"]\n            is_finished: Final = True\n            finish_reason: Final = \"stop\"\n            return {\n                \"text\": text,\n                \"is_finished\": is_finished,\n                \"finish_reason\": finish_reason,\n            }\n        except Exception:\n            raise ValueError(f\"Unable to parse response. Original response: {chunk}\")\n\n    def handle_maritalk_chunk(self, chunk):  # fake streaming\n        chunk = chunk.decode(\"utf-8\")\n        data_json: Final[_MaritalkStreamData] = json.loads(chunk)\n        try:\n            text: Final = data_json[\"answer\"]\n            is_finished: Final = True\n            finish_reason: Final = \"stop\"\n            return {\n                \"text\": text,\n                \"is_finished\": is_finished,\n                \"finish_reason\": finish_reason,\n            }\n        except Exception:\n            raise ValueError(f\"Unable to parse response. Original response: {chunk}\")\n\n    def handle_nlp_cloud_chunk(self, chunk):\n        text = \"\"","sourceCodeStart":522,"sourceCodeEnd":558,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/streaming_handler.py#L522-L558","documentation":"AI21 streaming parser guard: the chunk JSON could not be parsed into the expected completions[0].data.text shape, so an exception is raised including the original raw chunk for debugging — the provider sent an unexpected stream payload.","triggerScenarios":"Thrown at litellm/litellm_core_utils/streaming_handler.py:540 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["The provider returned a non-JSON or malformed chunk; log the original response and validate the endpoint.","Check for proxies modifying the response body."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}