{"record":{"id":"fddb6e4642baccd1","repo":"BerriAI/litellm","slug":"chunk","errorCode":null,"errorMessage":"chunk","messagePattern":"chunk","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/streaming_handler.py","lineNumber":518,"sourceCode":"                print_verbose(f\"data json: {data_json}\")\n                if \"token\" in data_json and \"text\" in data_json[\"token\"]:\n                    text = data_json[\"token\"][\"text\"]\n                if data_json.get(\"details\", False) and data_json[\"details\"].get(\"finish_reason\", False):\n                    is_finished = True\n                    finish_reason = data_json[\"details\"][\"finish_reason\"]\n                elif data_json.get(\"generated_text\", False):  # if full generated text exists, then stream is complete\n                    text = \"\"  # don't return the final bos token\n                    is_finished = True\n                    finish_reason = \"stop\"\n                elif data_json.get(\"error\", False):\n                    raise Exception(data_json.get(\"error\"))\n                return {\n                    \"text\": text,\n                    \"is_finished\": is_finished,\n                    \"finish_reason\": finish_reason,\n                }\n            elif \"error\" in chunk:\n                raise ValueError(chunk)\n            return {\n                \"text\": text,\n                \"is_finished\": is_finished,\n                \"finish_reason\": finish_reason,\n            }\n        except Exception as e:\n            raise e\n\n    def handle_ai21_chunk(self, chunk):  # fake streaming\n        chunk = chunk.decode(\"utf-8\")\n        data_json: Final[_Ai21StreamData] = json.loads(chunk)\n        try:\n            text: Final = data_json[\"completions\"][0][\"data\"][\"text\"]\n            is_finished: Final = True\n            finish_reason: Final = \"stop\"\n            return {\n                \"text\": text,\n                \"is_finished\": is_finished,","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/streaming_handler.py#L500-L536","documentation":"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.","triggerScenarios":"Thrown at litellm/litellm_core_utils/streaming_handler.py:518 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["The stream delivered an unexpected chunk; enable verbose logging to inspect raw chunks.","Check provider status and retry the streaming request."],"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"}