{"record":{"id":"f35684f225f67b94","repo":"BerriAI/litellm","slug":"bedrockexception-error-str-enable-litellm-m","errorCode":null,"errorMessage":"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.","messagePattern":"BedrockException - (.+?)\n\\. Enable 'litellm\\.modify_params=True' \\(for PROXY do: `litellm_settings::modify_params: True`\\) to insert a dummy assistant message and fix this error\\.","errorType":"exception","errorClass":"BadRequestError","httpStatus":400,"severity":"error","filePath":"litellm/litellm_core_utils/exception_mapping_utils.py","lineNumber":838,"sourceCode":"    exception_type: str,\n    exception_provider: str,\n    extra_information: str,\n) -> None:\n    if (\n        \"too many tokens\" in error_str\n        or \"expected maxLength:\" in error_str\n        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),","sourceCodeStart":820,"sourceCodeEnd":856,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/exception_mapping_utils.py#L820-L856","documentation":"LiteLLM throws BadRequestError when Bedrock's Converse API rejects the message list because conversation blocks and tool result blocks appear in the same turn (a user turn carries tool results while assistant content is also present). LiteLLM can auto-repair this shape by inserting a dummy assistant message, but only when litellm.modify_params is enabled; the exception message spells out that exact setting. It is a client-side (400) error: same payload plus modify_params=True succeeds.","triggerScenarios":"Calling litellm.completion(model='bedrock/...', tools=[...]) for the turn after a tool call, where the follow-up messages array places tool results and conversation blocks in one turn - typical when hand-building tool-response messages with OpenAI-style role='tool' ordering instead of the Converse-required assistant tool_use -> tool result -> user sequence.","commonSituations":"Agent loops that append tool output as a user message right after the assistant tool_use turn; porting OpenAI tool-calling code to Bedrock without reordering messages; default-safe litellm.modify_params=False so the dummy assistant message is never inserted.","solutions":["Enable the fix: litellm.modify_params = True in code (env LITELLM_MODIFY_PARAMS=True), or on the proxy litellm_settings: modify_params: True, so LiteLLM inserts the dummy assistant message","Restructure messages yourself: put tool results in their own turn per Bedrock Converse rules (assistant tool_use turn, then tool-result turn, then next user text)","Upgrade litellm - Bedrock tool-turn transformation receives ongoing fixes","If you must keep modify_params off, insert a minimal assistant message ({'role':'assistant','content':'.'}) before the tool results"],"exampleFix":"# before\nlitellm.completion(model=\"bedrock/anthropic.claude-3-sonnet-...\")  # raises: Conversation blocks and tool result blocks in same turn\n\n# after\nimport litellm\nlitellm.modify_params = True\nlitellm.completion(model=\"bedrock/anthropic.claude-3-sonnet-...\", messages=messages, tools=tools)","handlingStrategy":"validation","validationCode":"import litellm\nlitellm.modify_params = True  # let LiteLLM insert the dummy assistant message\n\ndef bedrock_safe_messages(messages: list) -> list:\n    out = []\n    for m in messages:\n        if m.get('role') == 'tool' and (not out or out[-1].get('role') != 'assistant'):\n            out.append({'role': 'assistant', 'content': '.'})  # dummy assistant turn\n        out.append(m)\n    return out","typeGuard":"import litellm\n\ndef is_bedrock_bad_request(e: BaseException) -> bool:\n    return isinstance(e, litellm.BadRequestError) and 'tool result blocks' in str(e)","tryCatchPattern":"try:\n    resp = litellm.completion(model='bedrock/...', messages=messages, tools=tools)\nexcept litellm.BadRequestError as e:\n    if 'tool result blocks' in str(e):\n        litellm.modify_params = True\n        resp = litellm.completion(model='bedrock/...', messages=messages, tools=tools)\n    else:\n        raise","preventionTips":["Keep litellm.modify_params=True when doing tool calling on Bedrock Converse models","Always order tool turns as assistant tool_use -> tool result -> next user message","Test agent tool loops against Bedrock specifically, not just OpenAI","After trimming history, re-validate that each tool result is preceded by an assistant turn"],"tags":["bedrock","tool-calling","message-ordering","modify-params","converse-api"],"backgroundTag":"tool-result-message-ordering","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}