{"record":{"id":"434b35e50d2f12a4","repo":"BerriAI/litellm","slug":"failed-to-decode-chunk-chunk-data-error-e","errorCode":null,"errorMessage":"Failed to decode chunk: {chunk_data}. Error: {e}","messagePattern":"Failed to decode chunk: (.+?)\\. Error: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/bedrock/chat/invoke_handler.py","lineNumber":822,"sourceCode":"                        arguments=_model_response_tool_call[0].function.arguments,\n                    ),\n                    index=0,\n                )\n            processed_chunk: Final = GChunk(\n                text=text,\n                tool_use=tool_use,\n                is_finished=True,\n                finish_reason=map_finish_reason(finish_reason=chunk_data.choices[0].finish_reason or \"\"),\n                usage=ChatCompletionUsageBlock(\n                    prompt_tokens=chunk_usage.prompt_tokens,\n                    completion_tokens=chunk_usage.completion_tokens,\n                    total_tokens=chunk_usage.total_tokens,\n                ),\n                index=0,\n            )\n            return processed_chunk\n        except Exception as e:\n            raise ValueError(f\"Failed to decode chunk: {chunk_data}. Error: {e}\")\n\n    def __next__(self):\n        if self.is_done:\n            raise StopIteration\n        self.is_done = True\n        return self._chunk_parser(self.model_response)\n\n    # Async iterator\n    def __aiter__(self):\n        return self\n\n    async def __anext__(self):\n        if self.is_done:\n            raise StopAsyncIteration\n        self.is_done = True\n        return self._chunk_parser(self.model_response)\n","sourceCodeStart":804,"sourceCodeEnd":839,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/bedrock/chat/invoke_handler.py#L804-L839","documentation":"Decode failure in the Bedrock streaming chunk parser: the raw chunk_data payload could not be decoded/parsed (malformed JSON or unexpected structure), and the wrapping handler reports both the offending chunk and the decode exception.","triggerScenarios":"Thrown at litellm/llms/bedrock/chat/invoke_handler.py:822 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check network stability; corrupted chunks often indicate connection issues.","Retry the request to get a clean stream.","Upgrade botocore/litellm if the event-stream codec mismatches the service."],"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"}