BerriAI/litellm · error · ValueError
Failed to decode chunk
Error message
Failed to decode chunk: {chunk_data}. Error: {e} What it means
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.
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.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at litellm/llms/bedrock/chat/invoke_handler.py:822 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/434b35e50d2f12a4.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/bedrock/chat/invoke_handler.py:822
arguments=_model_response_tool_call[0].function.arguments,
),
index=0,
)
processed_chunk: Final = GChunk(
text=text,
tool_use=tool_use,
is_finished=True,
finish_reason=map_finish_reason(finish_reason=chunk_data.choices[0].finish_reason or ""),
usage=ChatCompletionUsageBlock(
prompt_tokens=chunk_usage.prompt_tokens,
completion_tokens=chunk_usage.completion_tokens,
total_tokens=chunk_usage.total_tokens,
),
index=0,
)
return processed_chunk
except Exception as e:
raise ValueError(f"Failed to decode chunk: {chunk_data}. Error: {e}")
def __next__(self):
if self.is_done:
raise StopIteration
self.is_done = True
return self._chunk_parser(self.model_response)
# Async iterator
def __aiter__(self):
return self
async def __anext__(self):
if self.is_done:
raise StopAsyncIteration
self.is_done = True
return self._chunk_parser(self.model_response)
View on GitHub (pinned to 77b7c6c40c)