{"record":{"id":"7b3cba273c4ed980","repo":"BerriAI/litellm","slug":"error-parsing-received-text-outputtext-nerror","errorCode":null,"errorMessage":"Error parsing received text={outputText}.\\nError-{e}","messagePattern":"Error parsing received text=(.+?)\\.\\\\nError-(.+?)","errorType":"http","errorClass":"BedrockError","httpStatus":null,"severity":"warning","filePath":"litellm/llms/bedrock/chat/invoke_transformations/base_invoke_transformation.py","lineNumber":379,"sourceCode":"            )\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:\n                raise Exception()\n        except Exception as e:\n            raise BedrockError(\n                message=f\"Error parsing received text={outputText}.\\nError-{e}\",\n                status_code=raw_response.status_code,\n            )\n\n        ## CALCULATING USAGE - bedrock returns usage in the headers\n        bedrock_input_tokens: Final = raw_response.headers.get(\"x-amzn-bedrock-input-token-count\", None)\n        bedrock_output_tokens: Final = raw_response.headers.get(\"x-amzn-bedrock-output-token-count\", None)\n\n        prompt_tokens: Final = int(bedrock_input_tokens or litellm.token_counter(messages=messages))\n\n        completion_tokens: Final = int(\n            bedrock_output_tokens\n            or litellm.token_counter(\n                text=model_response.choices[0].message.content,\n                count_response_tokens=True,\n            )\n        )\n","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/bedrock/chat/invoke_transformations/base_invoke_transformation.py#L361-L397","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check whether outputText in the message is empty - if so, inspect why the model returned no text (filters, max_tokens).","Raise max_tokens and retest to confirm truncation is not the cause.","If guardrails are applied, check the guardrail trace to see if content was blocked.","Switch to bedrock/converse/<model> which tolerates empty content without raising."],"exampleFix":"# before\nresp = litellm.completion(model=\"bedrock/meta.llama3-8b-instruct-v1:0\", messages=msgs, max_tokens=1)\n\n# after\nresp = litellm.completion(\n    model=\"bedrock/converse/meta.llama3-8b-instruct-v1:0\",\n    messages=msgs,\n    max_tokens=512,\n)","handlingStrategy":"fallback","validationCode":"if max_tokens is not None and max_tokens < 16:\n    raise ValueError(\"max_tokens below 16 often yields empty outputText on the invoke route\")","typeGuard":null,"tryCatchPattern":"from litellm.exceptions import BedrockError\ntry:\n    resp = litellm.completion(model=\"bedrock/<provider>.<model>\", messages=msgs)\nexcept BedrockError as e:\n    if \"Error parsing received text\" in str(e):\n        # empty output: fall back to converse which tolerates empty content\n        resp = litellm.completion(model=\"bedrock/converse/<provider>.<model>\", messages=msgs)\n    else:\n        raise","preventionTips":["Keep max_tokens above a minimum threshold on the invoke route.","Design callers to handle empty content instead of assuming non-empty text.","Migrate to the converse route for tolerance of empty generations."],"tags":["aws","bedrock","empty-response","response-mapping","converse"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}