{"record":{"id":"a03ac9c3ded2b66d","repo":"BerriAI/litellm","slug":"error-processing-raw-response-text-received-err","errorCode":null,"errorMessage":"Error processing={raw_response.text}, Received error={e}","messagePattern":"Error processing=(.+?), Received error=(.+?)","errorType":"http","errorClass":"BedrockError","httpStatus":422,"severity":"error","filePath":"litellm/llms/bedrock/chat/invoke_transformations/base_invoke_transformation.py","lineNumber":358,"sourceCode":"                    logging_obj=logging_obj,\n                    request_data=request_data,\n                    messages=messages,\n                    optional_params=optional_params,\n                    litellm_params=litellm_params,\n                    encoding=encoding,\n                    api_key=api_key,\n                    json_mode=json_mode,\n                )\n            elif provider == \"ai21\":\n                outputText = completion_response.get(\"completions\")[0].get(\"data\").get(\"text\")\n            elif provider == \"meta\" or provider == \"llama\" or provider == \"deepseek_r1\":\n                outputText = completion_response[\"generation\"]\n            elif provider == \"mistral\":\n                outputText = litellm.AmazonMistralConfig.get_outputText(completion_response, model_response)\n            else:  # amazon titan\n                outputText = completion_response.get(\"results\")[0].get(\"outputText\")\n        except Exception as e:\n            raise BedrockError(\n                message=f\"Error processing={raw_response.text}, Received error={e}\",\n                status_code=422,\n            )\n\n        try:\n            if (\n                outputText is not None\n                and len(outputText) > 0\n                and hasattr(model_response.choices[0], \"message\")\n                and getattr(model_response.choices[0].message, \"tool_calls\", None) is None\n            ):\n                model_response.choices[0].message.content = outputText\n            elif (\n                hasattr(model_response.choices[0], \"message\")\n                and getattr(model_response.choices[0].message, \"tool_calls\", None) is not None\n            ):\n                pass\n            else:","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/bedrock/chat/invoke_transformations/base_invoke_transformation.py#L340-L376","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect raw_response.text in the error message - it shows the exact JSON and reveals what shape arrived.","If the body is an AWS error message, fix the underlying cause (model access, request validity) rather than parsing.","Correct the model string so the provider segment matches the actual model owner (bedrock/meta.llama3-..., bedrock/ai21.j2-...).","Move to bedrock/converse/<model> for a single stable response schema across providers."],"exampleFix":"# before\nresp = litellm.completion(model=\"bedrock/llama3-70b-instruct-v1:0\", messages=msgs)  # ambiguous provider segment\n\n# after\nresp = litellm.completion(model=\"bedrock/meta.llama3-70b-instruct-v1:0\", messages=msgs)\n# or use the unified route\nresp = litellm.completion(model=\"bedrock/converse/meta.llama3-70b-instruct-v1:0\", messages=msgs)","handlingStrategy":"validation","validationCode":"import re\nKNOWN_INVOKE_PREFIXES = (\"anthropic.\", \"cohere.\", \"ai21.\", \"meta.\", \"llama\", \"mistral.\", \"amazon.\", \"openai.\", \"us.anthropic.\", \"eu.anthropic.\")\ndef model_uses_invoke_parser(model_id: str) -> bool:\n    return any(model_id.startswith(p) for p in KNOWN_INVOKE_PREFIXES)","typeGuard":null,"tryCatchPattern":"from litellm.exceptions import BedrockError\ntry:\n    resp = litellm.completion(model=model, messages=msgs)\nexcept BedrockError as e:\n    if e.status_code == 422 and \"Error processing\" in str(e):\n        # response shape did not match the inferred provider - inspect raw body in message\n        log.error(\"unexpected provider payload: %s\", e.message)\n    raise","preventionTips":["Use fully-qualified model IDs with the correct owner prefix (meta., cohere., ai21.).","Prefer bedrock/converse/<model> for stable response schemas.","Log the raw response body on 422 to catch provider/shape mismatches early."],"tags":["aws","bedrock","response-parsing","provider-mapping","model-id"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}