{"record":{"id":"fddb6e4642baccd1","repo":"BerriAI/litellm","slug":"chunk","errorCode":null,"errorMessage":"chunk","messagePattern":"chunk","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/streaming_handler.py","lineNumber":491,"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":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/streaming_handler.py#L473-L509","documentation":"Second guard in the Predibase handler: if the raw (non-SSE) chunk string itself contains the substring 'error', the whole chunk is re-raised as ValueError, because a chunk-level 'error' token means the stream body is an error response rather than token data.","triggerScenarios":"Non-stream-shaped or error responses from Predibase that reach the streaming parser — e.g. a JSON error body delivered as one chunk, or proxy/gateway error text containing the word 'error'.","commonSituations":"Corporate proxies returning HTML/text error pages; Predibase returning a non-SSE JSON error; mismatch between stream=True and the endpoint's actual behavior.","solutions":["Print the chunk captured in the ValueError to identify the producer (Predibase vs proxy).","Fix the underlying request (auth, model id) that caused the error response.","If a proxy injects error pages, bypass it or fix its configuration for SSE endpoints."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    for part in stream:\n        ...\nexcept ValueError as e:\n    if \"predibase\" in str(e) or \"error\" in str(e).lower():\n        diagnose_from_chunk(str(e))","preventionTips":["Bypass transforming proxies for SSE endpoints.","Log the raw failing chunk at debug level to identify error sources fast."],"tags":["predibase","streaming","error-handling","provider"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}