BerriAI/litellm · warning · BedrockError

Error parsing received text={outputText}.\nError-{e}

Error message

Error parsing received text={outputText}.\nError-{e}

What it means

Raised by BaseAmazonInvokeConfig.transform_response when the extracted outputText cannot be assigned onto the ModelResponse - either outputText is None/empty, or none of the expected message/tool_calls branches apply, causing an intentional bare Exception. The BedrockError uses the HTTP status code of the raw response and embeds the failing outputText.

Source

Thrown at litellm/llms/bedrock/chat/invoke_transformations/base_invoke_transformation.py:379

            )

        try:
            if (
                outputText is not None
                and len(outputText) > 0
                and hasattr(model_response.choices[0], "message")
                and getattr(model_response.choices[0].message, "tool_calls", None) is None
            ):
                model_response.choices[0].message.content = outputText
            elif (
                hasattr(model_response.choices[0], "message")
                and getattr(model_response.choices[0].message, "tool_calls", None) is not None
            ):
                pass
            else:
                raise Exception()
        except Exception as e:
            raise BedrockError(
                message=f"Error parsing received text={outputText}.\nError-{e}",
                status_code=raw_response.status_code,
            )

        ## CALCULATING USAGE - bedrock returns usage in the headers
        bedrock_input_tokens: Final = raw_response.headers.get("x-amzn-bedrock-input-token-count", None)
        bedrock_output_tokens: Final = raw_response.headers.get("x-amzn-bedrock-output-token-count", None)

        prompt_tokens: Final = int(bedrock_input_tokens or litellm.token_counter(messages=messages))

        completion_tokens: Final = int(
            bedrock_output_tokens
            or litellm.token_counter(
                text=model_response.choices[0].message.content,
                count_response_tokens=True,
            )
        )

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Check whether outputText in the message is empty - if so, inspect why the model returned no text (filters, max_tokens).
  2. Raise max_tokens and retest to confirm truncation is not the cause.
  3. If guardrails are applied, check the guardrail trace to see if content was blocked.
  4. Switch to bedrock/converse/<model> which tolerates empty content without raising.

Example fix

# before
resp = litellm.completion(model="bedrock/meta.llama3-8b-instruct-v1:0", messages=msgs, max_tokens=1)

# after
resp = litellm.completion(
    model="bedrock/converse/meta.llama3-8b-instruct-v1:0",
    messages=msgs,
    max_tokens=512,
)
Defensive patterns

Strategy: fallback

Validate before calling

if max_tokens is not None and max_tokens < 16:
    raise ValueError("max_tokens below 16 often yields empty outputText on the invoke route")

Try / catch

from litellm.exceptions import BedrockError
try:
    resp = litellm.completion(model="bedrock/<provider>.<model>", messages=msgs)
except BedrockError as e:
    if "Error parsing received text" in str(e):
        # empty output: fall back to converse which tolerates empty content
        resp = litellm.completion(model="bedrock/converse/<provider>.<model>", messages=msgs)
    else:
        raise

Prevention

When it happens

Trigger: A bedrock invoke completion that returns an empty outputText (empty generations from content filtering, max_tokens reached before any token, or empty model output) - the final else branch raises and the handler converts it to this error.

Common situations: Guardrails or provider-side filters blocking all content, max_tokens set extremely low, empty prompt edge cases, or providers legitimately returning empty text that this strict legacy parser treats as fatal.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/7b3cba273c4ed980. Report an issue: GitHub.