{"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/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/exception_mapping_utils.py#L820-L856","documentation":"Bedrock-specific: raised as BadRequestError when the error text contains 'Conversation blocks and tool result blocks cannot be provided in the same turn.' — i.e. your message list has a user turn containing both toolResult blocks and other conversation content, which the Bedrock Converse API forbids. The message tells you the fix: enable litellm.modify_params so LiteLLM inserts a dummy assistant message to satisfy Bedrock's schema.","triggerScenarios":"Sending an agentic transcript where a tool result is immediately followed by (or packed with) additional user content in the same turn — common after manual message-history manipulation or when the assistant tool_use turn is missing from history.","commonSituations":"Agent frameworks that append tool outputs plus a user message without an assistant turn in between; hand-built histories where the assistant's tool_use message was dropped; converting OpenAI-format tool messages to Bedrock converse format incorrectly.","solutions":["Set litellm.modify_params = True (or litellm_settings: modify_params: true in the proxy config) so LiteLLM inserts the required dummy assistant message.","Or fix the history yourself: ensure every tool result sits in a user turn that follows an assistant turn containing the corresponding tool_use, with no extra content in the tool-result turn.","Match every 'tool' role message to its preceding assistant tool_calls message."],"exampleFix":"# before\nimport litellm\nlitellm.modify_params = False\nresp = litellm.completion(model=\"bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0\", messages=agent_history_with_tool_results)\n\n# after\nimport litellm\nlitellm.modify_params = True\nresp = litellm.completion(model=\"bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0\", messages=agent_history_with_tool_results)","handlingStrategy":"validation","validationCode":"def history_tool_blocks_are_separated(messages: list) -> bool:\n    \"\"\"Every tool ('tool' role / toolResult) message must directly follow an assistant message containing tool_calls.\"n    for i, m in enumerate(messages):\n        if m.get(\"role\") == \"tool\":\n            if i == 0 or \"tool_calls\" not in (messages[i - 1] or {}):\n                return False\n            # no user content packed into the same turn as a tool result\n        if m.get(\"role\") == \"user\" and isinstance(m.get(\"content\"), list):\n            if any(b.get(\"type\") == \"tool_result\" for b in m[\"content\"]) and len(m[\"content\"]) > 1:\n                return False\n    return True","typeGuard":"import litellm\n\ndef is_bedrock_tool_turn_error(e: BaseException) -> bool:\n    return isinstance(e, litellm.BadRequestError) and \"cannot be provided in the same turn\" in str(e)","tryCatchPattern":"try:\n    resp = litellm.completion(model=\"bedrock/...\", messages=msgs)\nexcept litellm.BadRequestError as e:\n    if \"cannot be provided in the same turn\" in str(e):\n        msgs = insert_dummy_assistant_after_tool_results(msgs)\n        resp = litellm.completion(model=\"bedrock/...\", messages=msgs)\n    else:\n        raise","preventionTips":["Enable litellm.modify_params = True for Bedrock agents using tools.","Always keep the assistant tool_calls message paired with its tool results in persisted history.","Validate tool-result ordering before replaying stored conversations."],"tags":["bedrock","tools","message-format","converse-api","litellm"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}