BerriAI/litellm · error · BedrockError

Error processing={raw_response.text}, Received error={e}

Error message

Error processing={raw_response.text}, Received error={e}

What it means

Raised by BaseAmazonInvokeConfig.transform_response when extracting output text from the parsed completion JSON fails for the recognized provider branch - e.g. ai21 completions[0].data.text missing, meta 'generation' key absent, or mistral get_outputText raising. It wraps the failure as BedrockError 422 including the raw response text and the underlying exception.

Source

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

                    logging_obj=logging_obj,
                    request_data=request_data,
                    messages=messages,
                    optional_params=optional_params,
                    litellm_params=litellm_params,
                    encoding=encoding,
                    api_key=api_key,
                    json_mode=json_mode,
                )
            elif provider == "ai21":
                outputText = completion_response.get("completions")[0].get("data").get("text")
            elif provider == "meta" or provider == "llama" or provider == "deepseek_r1":
                outputText = completion_response["generation"]
            elif provider == "mistral":
                outputText = litellm.AmazonMistralConfig.get_outputText(completion_response, model_response)
            else:  # amazon titan
                outputText = completion_response.get("results")[0].get("outputText")
        except Exception as e:
            raise BedrockError(
                message=f"Error processing={raw_response.text}, Received error={e}",
                status_code=422,
            )

        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:

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Inspect raw_response.text in the error message - it shows the exact JSON and reveals what shape arrived.
  2. If the body is an AWS error message, fix the underlying cause (model access, request validity) rather than parsing.
  3. Correct the model string so the provider segment matches the actual model owner (bedrock/meta.llama3-..., bedrock/ai21.j2-...).
  4. Move to bedrock/converse/<model> for a single stable response schema across providers.

Example fix

# before
resp = litellm.completion(model="bedrock/llama3-70b-instruct-v1:0", messages=msgs)  # ambiguous provider segment

# after
resp = litellm.completion(model="bedrock/meta.llama3-70b-instruct-v1:0", messages=msgs)
# or use the unified route
resp = litellm.completion(model="bedrock/converse/meta.llama3-70b-instruct-v1:0", messages=msgs)
Defensive patterns

Strategy: validation

Validate before calling

import re
KNOWN_INVOKE_PREFIXES = ("anthropic.", "cohere.", "ai21.", "meta.", "llama", "mistral.", "amazon.", "openai.", "us.anthropic.", "eu.anthropic.")
def model_uses_invoke_parser(model_id: str) -> bool:
    return any(model_id.startswith(p) for p in KNOWN_INVOKE_PREFIXES)

Try / catch

from litellm.exceptions import BedrockError
try:
    resp = litellm.completion(model=model, messages=msgs)
except BedrockError as e:
    if e.status_code == 422 and "Error processing" in str(e):
        # response shape did not match the inferred provider - inspect raw body in message
        log.error("unexpected provider payload: %s", e.message)
    raise

Prevention

When it happens

Trigger: A provider response whose JSON parses but lacks the expected keys: AI21 responses without 'completions', Titan without 'results', Llama without 'generation' - typically because the body is actually an AWS error JSON ({'message': ...}) with a 200, or the model/provider mapping is wrong.

Common situations: Wrong provider inferred from the model string (e.g. bedrock/llama3-... vs bedrock/meta.llama3-...), model version changes altering response shape, or Bedrock returning error JSON that slipped through the status check.

Related errors


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