{"record":{"id":"20f05baaa0f3245d","repo":"BerriAI/litellm","slug":"failed-to-parse-v2-chunk-e-chunk-chunk","errorCode":null,"errorMessage":"Failed to parse v2 chunk: {e}, chunk: {chunk}","messagePattern":"Failed to parse v2 chunk: (.+?), chunk: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/cohere/common_utils.py","lineNumber":350,"sourceCode":"\n            # Handle citations in any chunk type (fallback)\n            if \"citations\" in chunk:\n                if provider_specific_fields is None:\n                    provider_specific_fields = {}\n                provider_specific_fields[\"citations\"] = chunk[\"citations\"]\n\n            return GenericStreamingChunk(\n                text=text,\n                tool_use=tool_use,\n                is_finished=is_finished,\n                finish_reason=finish_reason,\n                usage=usage,\n                index=index,\n                provider_specific_fields=provider_specific_fields,\n            )\n\n        except Exception as e:\n            raise ValueError(f\"Failed to parse v2 chunk: {e}, chunk: {chunk}\")\n\n    # Sync iterator\n    def __iter__(self):\n        return self\n\n    def __next__(self):\n        try:\n            chunk: Final = self.response_iterator.__next__()\n        except StopIteration:\n            raise StopIteration\n        except ValueError as e:\n            raise RuntimeError(f\"Error receiving chunk from stream: {e}\")\n\n        try:\n            return self.convert_str_chunk_to_generic_chunk(chunk=chunk)\n        except StopIteration:\n            raise StopIteration\n        except ValueError as e:","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/cohere/common_utils.py#L332-L368","documentation":"Parse failure in the Cohere v2 streaming chunk parser: transforming the incoming chunk dict into a GenericStreamingChunk raised, and the handler reports both the exception and the offending chunk payload for diagnosis.","triggerScenarios":"Thrown at litellm/llms/cohere/common_utils.py:350 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the logged chunk; the Cohere v2 stream sent data that is not valid JSON or not the expected event shape.","Upgrade litellm to the latest version; Cohere v2 streaming event formats have changed and newer releases handle them.","If the chunk is a non-JSON SSE control line (e.g. '[DONE]'), filter such lines before parsing in your own stream handling."],"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"}