BerriAI/litellm · error · BedrockError
Error parsing received text={outputText}. Error-{e}
Error message
Error parsing received text={outputText}.
Error-{e} What it means
Assignment failure while writing outputText into the model response: the extracted text could not be set on choices[0].message.content because the response object lacked the expected shape, and the handler appends the parse exception for diagnosis.
Source
Thrown at litellm/llms/bedrock/chat/invoke_transformations/base_invoke_transformation.py:383
)
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 77b7c6c40c)
Solutions
- Check outputText for malformed or unexpected content from the model.
- Retry the request; parsing failures can be transient.
- Upgrade litellm if the provider response format changed.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at litellm/llms/bedrock/chat/invoke_transformations/base_invoke_transformation.py:383 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/527157ed324f8c02.
Report an issue: GitHub.