{"record":{"id":"0c2f16828cc54647","repo":"BerriAI/litellm","slug":"error-receiving-chunk-from-stream-e-0c2f16","errorCode":null,"errorMessage":"Error receiving chunk from stream: {e}","messagePattern":"Error receiving chunk from stream: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"litellm/llms/databricks/streaming_utils.py","lineNumber":105,"sourceCode":"                index=0,\n            )\n        except json.JSONDecodeError:\n            raise ValueError(f\"Failed to decode JSON from chunk: {chunk}\")\n\n    # Sync iterator\n    def __iter__(self):\n        self.response_iterator = self.streaming_response\n        return self\n\n    def __next__(self):\n        if not hasattr(self, \"response_iterator\"):\n            self.response_iterator = self.streaming_response\n        try:\n            chunk = self.response_iterator.__next__()\n        except StopIteration:\n            raise StopIteration\n        except ValueError as e:\n            raise RuntimeError(f\"Error receiving chunk from stream: {e}\")\n\n        try:\n            chunk = litellm.CustomStreamWrapper._strip_sse_data_from_chunk(chunk) or \"\"\n            chunk = chunk.strip()\n            if len(chunk) > 0:\n                json_chunk: Final = json.loads(chunk)\n                return self.chunk_parser(chunk=json_chunk)\n            else:\n                return GenericStreamingChunk(\n                    text=\"\",\n                    is_finished=False,\n                    finish_reason=\"\",\n                    usage=None,\n                    index=0,\n                    tool_use=None,\n                )\n        except StopIteration:\n            raise StopIteration","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/databricks/streaming_utils.py#L87-L123","documentation":"Raised by the sync Databricks streaming iterator when pulling the next chunk from the underlying response raises a ValueError (per the code, chiefly the JSON-decode failure from chunk_parser). The original error text is embedded in a RuntimeError, aborting iteration of the stream.","triggerScenarios":"Iterating a synchronous Databricks stream (for chunk in response:) where the transport raises a ValueError while reading the next SSE line — most commonly the 'Failed to decode JSON from chunk' failure propagated from the parser.","commonSituations":"Sync consumers of long Databricks streams through flaky proxies; streams cut mid-event by idle timeouts; partial event delivery under load.","solutions":["Inspect the embedded inner message to find the raw chunk that failed to parse","Add retry logic around the whole completion request for stream read failures","Tune or disable proxy buffering/idle timeouts on the path to Databricks","Consider non-streaming mode for unstable network paths"],"exampleFix":"# before\nfor chunk in response:\n    print(chunk)\n\n# after\ntry:\n    for chunk in response:\n        print(chunk)\nexcept RuntimeError as e:\n    logger.error(\"stream failed: %s\", e)\n    response = litellm.completion(**params)  # retry once\n    for chunk in response:\n        print(chunk)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for attempt in range(2):\n    try:\n        response = litellm.completion(**params, stream=True)\n        for chunk in response:\n            handle(chunk)\n        break\n    except RuntimeError as e:\n        if attempt == 1 or \"Error receiving chunk from stream\" not in str(e):\n            raise","preventionTips":["Wrap sync stream consumption in a bounded retry that restarts the whole completion call","For long streams, prefer checkpointed consumption so a retry can resume from the last handled chunk"],"tags":["databricks","streaming","sync","error-handling"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}