{"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":"exception","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/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/cohere/common_utils.py#L332-L368","documentation":"The Cohere v2 streaming chunk parser wraps its entire conversion in a broad except Exception: any failure while turning a v2 SSE event into a GenericStreamingChunk (missing expected fields like type/delta, unexpected event type, JSON issues after data: stripping) becomes ValueError('Failed to parse v2 chunk: {e}, chunk: {chunk}') including the original exception and raw chunk.","triggerScenarios":"Streaming cohere v2 models (command-r, command-r-plus, command-a) when an SSE event deviates from the expected v2 shapes: new event types introduced by Cohere (e.g. new content-block events), malformed data payloads, or in-stream error events.","commonSituations":"Schema drift: Cohere adds event types and the installed litellm version cannot parse them; tool-use streams with event sequences the parser does not cover; truncated events from network faults.","solutions":["Read the embedded chunk and exception: an unrecognized 'type' field means schema drift — upgrade litellm.","An in-stream error event points to a request-level cause (context length, moderation) — fix and retry.","Truncated payloads indicate transport issues — retry with backoff.","Report unrecognized-but-valid event types to the litellm repo with the chunk payload."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    for chunk in cohere_v2_stream:\n        consume(chunk)\nexcept ValueError as e:\n    if \"Failed to parse v2 chunk\" in str(e):\n        if is_unknown_event_type(str(e)):\n            file_litellm_issue_with_chunk(str(e))\n        retry_stream()  # truncated/error events are often transient\n    raise","preventionTips":["Track litellm release notes for Cohere v2 stream support updates and upgrade promptly.","Model tool-use and citation flows explicitly in tests — these emit the richest event sets.","Capture the raw chunk on failure; it distinguishes schema drift from transient errors."],"tags":["cohere","streaming","v2","schema-validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}