BerriAI/litellm · error · BadRequestError
BedrockException - {error_str}
Error message
BedrockException - {error_str} What it means
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.
Source
Thrown at litellm/litellm_core_utils/exception_mapping_utils.py:845
or "Input is too long" in error_str
or "prompt is too long" in error_str
or "prompt: length: 1.." in error_str
or "Too many input tokens" in error_str
):
raise ContextWindowExceededError(
message=f"BedrockException: Context Window Error - {error_str}",
model=model,
llm_provider="bedrock",
)
elif "Conversation blocks and tool result blocks cannot be provided in the same turn." in error_str:
raise BadRequestError(
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.",
model=model,
llm_provider="bedrock",
response=getattr(original_exception, "response", None),
)
elif "Malformed input request" in error_str:
raise BadRequestError(
message=f"BedrockException - {error_str}",
model=model,
llm_provider="bedrock",
response=getattr(original_exception, "response", None),
)
elif "A conversation must start with a user message." in error_str:
raise BadRequestError(
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`",
model=model,
llm_provider="bedrock",
response=getattr(original_exception, "response", None),
)
elif (
"Unable to locate credentials" in error_str
or "The security token included in the request is invalid" in error_str
):
raise AuthenticationError(
message=f"BedrockException Invalid Authentication - {error_str}",View on GitHub (pinned to 6c2dcb801b)
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).
Example fix
# before
resp = litellm.completion(model="bedrock/meta.llama3-8b-instruct-v1:0", messages=[{"role": "system", "content": "..."}, {"role": "user", "content": [{"type": "image_url", "image_url": {...}}]}])
# after
resp = litellm.completion(model="bedrock/meta.llama3-8b-instruct-v1:0", messages=[{"role": "user", "content": "describe this: ..."}]) # text-only model: no image blocks Defensive patterns
Strategy: validation
Validate before calling
def bedrock_messages_well_formed(messages: list) -> bool:
if not messages:
return False
non_system = [m for m in messages if m.get("role") != "system"]
if not non_system or non_system[0].get("role") != "user":
return False
for m in non_system:
content = m.get("content")
if content is None:
return False
if isinstance(content, list):
for b in content:
if b.get("type") not in {"text", "image_url", "tool_use", "tool_result"}:
return False
return True Type guard
import litellm
def is_bedrock_malformed(e: BaseException) -> bool:
return isinstance(e, litellm.BadRequestError) and "Malformed input request" in str(e) Try / catch
try:
resp = litellm.completion(model="bedrock/...", messages=msgs)
except litellm.BadRequestError as e:
if "Malformed input request" in str(e):
log.error("payload rejected by bedrock: %s", msgs) # fix structure; do not retry unchanged
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid template message type: {type(template_message)}
- {custom_llm_provider.capitalize()}Exception - Use 'watsonx_t
- BedrockException: Context Window Error - {error_str}
- BedrockException - {error_str} . Enable 'litellm.modify_para
- BedrockException - {error_str} . Pass in default user messag
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/09cd08c01bdd5ff3.
Report an issue: GitHub.