BerriAI/litellm · error · ValueError
chunk
Error message
chunk
What it means
Streaming chunk handler guard: a raw chunk that failed provider-specific parsing is raised/logged bare ('chunk') when the handler cannot extract text — a sentinel indicating an unparseable or unexpected chunk shape for the current provider.
Solutions
- The stream delivered an unexpected chunk; enable verbose logging to inspect raw chunks.
- Check provider status and retry the streaming request.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at litellm/litellm_core_utils/streaming_handler.py:518 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/fddb6e4642baccd1.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/litellm_core_utils/streaming_handler.py:518
print_verbose(f"data json: {data_json}")
if "token" in data_json and "text" in data_json["token"]:
text = data_json["token"]["text"]
if data_json.get("details", False) and data_json["details"].get("finish_reason", False):
is_finished = True
finish_reason = data_json["details"]["finish_reason"]
elif data_json.get("generated_text", False): # if full generated text exists, then stream is complete
text = "" # don't return the final bos token
is_finished = True
finish_reason = "stop"
elif data_json.get("error", False):
raise Exception(data_json.get("error"))
return {
"text": text,
"is_finished": is_finished,
"finish_reason": finish_reason,
}
elif "error" in chunk:
raise ValueError(chunk)
return {
"text": text,
"is_finished": is_finished,
"finish_reason": finish_reason,
}
except Exception as e:
raise e
def handle_ai21_chunk(self, chunk): # fake streaming
chunk = chunk.decode("utf-8")
data_json: Final[_Ai21StreamData] = json.loads(chunk)
try:
text: Final = data_json["completions"][0]["data"]["text"]
is_finished: Final = True
finish_reason: Final = "stop"
return {
"text": text,
"is_finished": is_finished,View on GitHub (pinned to 77b7c6c40c)