{"record":{"id":"b0b090ac01d49c03","repo":"BerriAI/litellm","slug":"str-mapped-exception","errorCode":null,"errorMessage":"str(mapped_exception)","messagePattern":"str\\(mapped_exception\\)","errorType":"exception","errorClass":"MidStreamFallbackError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/streaming_handler.py","lineNumber":2381,"sourceCode":"                    status_code: Final[int | str | None] = getattr(response, \"status_code\", None)\n                    if status_code is not None:\n                        return int(status_code)\n                except Exception:\n                    pass\n            return None\n\n        mapped_status_code: Final = _normalize_status_code(mapped_exception)\n        original_status_code: Final = _normalize_status_code(e)\n\n        # Raise non-retriable client errors directly (skip fallback).\n        # Exception: 429 (rate-limit) IS retriable/transient — allow it\n        # through so the Router can switch to a different model group.\n        if mapped_status_code is not None and 400 <= mapped_status_code < 500 and mapped_status_code != 429:\n            raise mapped_exception\n        if original_status_code is not None and 400 <= original_status_code < 500 and original_status_code != 429:\n            raise mapped_exception\n\n        raise MidStreamFallbackError(\n            message=str(mapped_exception),\n            model=self.model,\n            llm_provider=self.custom_llm_provider or \"anthropic\",\n            original_exception=mapped_exception,\n            generated_content=self.response_uptil_now,\n            is_pre_first_chunk=not self.sent_first_chunk,\n        )\n\n    @staticmethod\n    def _strip_sse_data_from_chunk(chunk: str | None) -> str | None:\n        \"\"\"\n        Strips the 'data: ' prefix from Server-Sent Events (SSE) chunks.\n\n        Some providers like sagemaker send it as `data:`, need to handle both\n\n        SSE messages are prefixed with 'data: ' which is part of the protocol,\n        not the actual content from the LLM. This method removes that prefix\n        and returns the actual content.","sourceCodeStart":2363,"sourceCodeEnd":2399,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/streaming_handler.py#L2363-L2399","documentation":"Router streaming fallback decision point: when a mid-stream exception occurs, the mapped exception's string is raised if the error is judged non-transient (e.g. client errors other than 429); the string form of the mapped exception becomes the surfaced error for the failing stream.","triggerScenarios":"Thrown at litellm/litellm_core_utils/streaming_handler.py:2381 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the mapped exception (str(mapped_exception)) with verbose logging for the root cause.","Fix the underlying request or configuration issue that produced the exception."],"exampleFix":null,"handlingStrategy":"fallback","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-14T05:17:10.506Z"}