{"record":{"id":"09cd08c01bdd5ff3","repo":"BerriAI/litellm","slug":"bedrockexception-error-str","errorCode":null,"errorMessage":"BedrockException - {error_str}","messagePattern":"BedrockException - (.+?)","errorType":"exception","errorClass":"BadRequestError","httpStatus":400,"severity":"error","filePath":"litellm/litellm_core_utils/exception_mapping_utils.py","lineNumber":845,"sourceCode":"        or \"Input is too long\" in error_str\n        or \"prompt is too long\" in error_str\n        or \"prompt: length: 1..\" in error_str\n        or \"Too many input tokens\" in error_str\n    ):\n        raise ContextWindowExceededError(\n            message=f\"BedrockException: Context Window Error - {error_str}\",\n            model=model,\n            llm_provider=\"bedrock\",\n        )\n    elif \"Conversation blocks and tool result blocks cannot be provided in the same turn.\" in error_str:\n        raise BadRequestError(\n            message=f\"BedrockException - {error_str}\\n. Enable 'litellm.modify_params=True' (for PROXY do: `litellm_settings::modify_params: True`) to insert a dummy assistant message and fix this error.\",\n            model=model,\n            llm_provider=\"bedrock\",\n            response=getattr(original_exception, \"response\", None),\n        )\n    elif \"Malformed input request\" in error_str:\n        raise BadRequestError(\n            message=f\"BedrockException - {error_str}\",\n            model=model,\n            llm_provider=\"bedrock\",\n            response=getattr(original_exception, \"response\", None),\n        )\n    elif \"A conversation must start with a user message.\" in error_str:\n        raise BadRequestError(\n            message=f\"BedrockException - {error_str}\\n. Pass in default user message via `completion(..,user_continue_message=)` or enable `litellm.modify_params=True`.\\nFor Proxy: do via `litellm_settings::modify_params: True` or user_continue_message under `litellm_params`\",\n            model=model,\n            llm_provider=\"bedrock\",\n            response=getattr(original_exception, \"response\", None),\n        )\n    elif (\n        \"Unable to locate credentials\" in error_str\n        or \"The security token included in the request is invalid\" in error_str\n    ):\n        raise AuthenticationError(\n            message=f\"BedrockException Invalid Authentication - {error_str}\",","sourceCodeStart":827,"sourceCodeEnd":863,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/exception_mapping_utils.py#L827-L863","documentation":"Bedrock-specific: BadRequestError raised when the error text contains 'Malformed input request'. The request body does not conform to the Bedrock Converse/InvokeModel schema for that model — a structural problem with the payload, not its content size.","triggerScenarios":"Invalid roles or role ordering, tool_use/toolResult blocks that do not pair up, unsupported content block types for the model (e.g. images sent to a text-only Bedrock model), or wrong inference-specific fields (inferenceConfig, toolConfig) for the model family.","commonSituations":"Using an OpenAI-format feature the Bedrock model does not support (system as a non-first message, images, json schema), version-specific schema differences between Bedrock model families (Titan vs Claude vs Llama), or hand-rolled request builders.","solutions":["Inspect the full error text after 'BedrockException - ' for the specific schema violation.","Let litellm build the payload (call litellm.completion with model='bedrock/...') instead of hand-crafting the body, and update litellm to the latest version.","Validate structure: first message system-like content in system=, alternating user/assistant, tool results paired with tool_use.","Remove content types the model family does not support (e.g. image blocks to text-only models)."],"exampleFix":"# before\nresp = litellm.completion(model=\"bedrock/meta.llama3-8b-instruct-v1:0\", messages=[{\"role\": \"system\", \"content\": \"...\"}, {\"role\": \"user\", \"content\": [{\"type\": \"image_url\", \"image_url\": {...}}]}])\n\n# after\nresp = litellm.completion(model=\"bedrock/meta.llama3-8b-instruct-v1:0\", messages=[{\"role\": \"user\", \"content\": \"describe this: ...\"}])  # text-only model: no image blocks","handlingStrategy":"validation","validationCode":"def bedrock_messages_well_formed(messages: list) -> bool:\n    if not messages:\n        return False\n    non_system = [m for m in messages if m.get(\"role\") != \"system\"]\n    if not non_system or non_system[0].get(\"role\") != \"user\":\n        return False\n    for m in non_system:\n        content = m.get(\"content\")\n        if content is None:\n            return False\n        if isinstance(content, list):\n            for b in content:\n                if b.get(\"type\") not in {\"text\", \"image_url\", \"tool_use\", \"tool_result\"}:\n                    return False\n    return True","typeGuard":"import litellm\n\ndef is_bedrock_malformed(e: BaseException) -> bool:\n    return isinstance(e, litellm.BadRequestError) and \"Malformed input request\" in str(e)","tryCatchPattern":"try:\n    resp = litellm.completion(model=\"bedrock/...\", messages=msgs)\nexcept litellm.BadRequestError as e:\n    if \"Malformed input request\" in str(e):\n        log.error(\"payload rejected by bedrock: %s\", msgs)  # fix structure; do not retry unchanged\n    raise","preventionTips":["Always go through litellm.completion with 'bedrock/' model strings rather than hand-building Converse payloads.","Match content block types to the model family (no image blocks for text-only models).","Update litellm promptly when AWS ships Converse API schema changes."],"tags":["bedrock","malformed-request","schema","bad-request","litellm"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}