{"record":{"id":"2bf944a31cd9fec4","repo":"BerriAI/litellm","slug":"bedrockexception-error-str-n-pass-in-default","errorCode":null,"errorMessage":"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`","messagePattern":"BedrockException - (.+?)\\\\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`","errorType":"exception","errorClass":"BadRequestError","httpStatus":400,"severity":"error","filePath":"litellm/litellm_core_utils/exception_mapping_utils.py","lineNumber":852,"sourceCode":"            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}\",\n            model=model,\n            llm_provider=\"bedrock\",\n            response=getattr(original_exception, \"response\", None),\n        )\n    elif \"AccessDeniedException\" in error_str:\n        raise PermissionDeniedError(\n            message=f\"BedrockException PermissionDeniedError - {error_str}\",","sourceCodeStart":834,"sourceCodeEnd":870,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/exception_mapping_utils.py#L834-L870","documentation":"LiteLLM throws BadRequestError when Bedrock Converse rejects a conversation whose first message is not from the user (typically it starts with an assistant or tool message). The mapper's message names the two supported remedies: pass user_continue_message=... to completion() so LiteLLM inserts a default user message, or enable litellm.modify_params=True (proxy: litellm_settings::modify_params: True). It is purely a message-ordering constraint of the Converse API, not a size or auth problem.","triggerScenarios":"messages=[{'role':'assistant',...}, ...] as the first element; history trimming that removes so many early turns the first surviving message is an assistant/tool turn; assistant-prefilled continuations that OpenAI tolerated but Bedrock Converse rejects as the opening turn.","commonSituations":"Chat apps that persist and reload trimmed histories; agent loops resuming from the model's previous answer; porting OpenAI-style conversations where assistant-first arrays were accepted.","solutions":["Pass user_continue_message='...' (or litellm_params user_continue_message on the proxy) so a default user message is prepended","Enable litellm.modify_params=True in code, or litellm_settings::modify_params: True on the proxy","Reorder locally: ensure messages[0]['role'] == 'user' before calling (prepend a user turn or drop leading assistant turns)","When trimming history, always keep or synthesize a leading user message"],"exampleFix":"# before\nmessages = [{'role': 'assistant', 'content': 'Continuing earlier answer...'}, ...]\nresp = litellm.completion(model=\"bedrock/...\", messages=messages)\n\n# after\nmessages = [{'role': 'user', 'content': 'Continue, please.'}] + messages\nresp = litellm.completion(model=\"bedrock/...\", messages=messages, user_continue_message='Continue, please.')","handlingStrategy":"validation","validationCode":"def starts_with_user(messages: list) -> bool:\n    return bool(messages) and messages[0].get('role') == 'user'\n\n# or pass a default so LiteLLM handles it:\n# litellm.completion(..., user_continue_message='Continue, please.')","typeGuard":"import litellm\n\ndef is_bad_request(e: BaseException) -> bool:\n    return isinstance(e, litellm.BadRequestError) and 'must start with a user message' in str(e)","tryCatchPattern":"try:\n    resp = litellm.completion(model='bedrock/...', messages=messages)\nexcept litellm.BadRequestError as e:\n    if 'must start with a user message' in str(e):\n        messages = [{'role': 'user', 'content': 'Continue, please.'}] + messages\n        resp = litellm.completion(model='bedrock/...', messages=messages)\n    else:\n        raise","preventionTips":["When trimming history, always keep or synthesize a leading user message","Pass user_continue_message= for Bedrock Converse calls by default","Validate messages[0]['role'] == 'user' before every bedrock call","Test resume-from-checkpoint flows where histories get truncated mid-conversation"],"tags":["bedrock","message-ordering","converse-api","modify-params"],"backgroundTag":"first-message-must-be-user","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}