BerriAI/litellm · error · SagemakerError

SageMaker event-stream shape could not be loaded from botoco

Error message

SageMaker event-stream shape could not be loaded from botocore. Ensure botocore is correctly installed.

What it means

Event-stream decoder guard: get_sagemaker_response_stream_shape() returned None because botocore could not supply the SageMaker response stream shape, so events cannot be decoded; raised with status 500.

Source

Thrown at litellm/llms/sagemaker/common_utils.py:196

        # Handle any remaining data after the iterator is exhausted
        if accumulated_json:
            try:
                _data = json.loads(accumulated_json)
                if self.is_messages_api:
                    yield self._chunk_parser_messages_api(chunk_data=_data)
                else:
                    yield self._chunk_parser(chunk_data=_data)
            except json.JSONDecodeError:
                # Handle or log any unparseable data at the end
                verbose_logger.error("Warning: Unparseable JSON data remained: %s", accumulated_json)
                yield None
            except Exception as e:
                verbose_logger.error("Final error parsing accumulated JSON: %s", e)

    def _parse_message_from_event(self, event) -> str | None:
        response_stream_shape: Final = get_sagemaker_response_stream_shape()
        if response_stream_shape is None:
            raise SagemakerError(
                status_code=500,
                message=(
                    "SageMaker event-stream shape could not be loaded from botocore. "
                    "Ensure botocore is correctly installed."
                ),
            )
        response_dict: Final = event.to_response_dict()
        parsed_response: Final = self.parser.parse(response_dict, response_stream_shape)

        if response_dict["status_code"] != 200:
            raise ValueError(f"Bad response code, expected 200: {response_dict}")

        if "chunk" in parsed_response:
            chunk = parsed_response.get("chunk")
            if not chunk:
                return None
            return chunk.get("bytes").decode()
        else:

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Reinstall or upgrade botocore so the event-stream shape is available.
  2. Ensure boto3/botocore versions are compatible.

Example fix

pip install -U boto3 botocore
Defensive patterns

Strategy: validation

When it happens

Trigger: Triggered when the SageMaker event-stream shape cannot be loaded from botocore, indicating a broken botocore installation.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/7402286e8ad328a4. Report an issue: GitHub.