From bc29b90c1dbc93bc6a0033ad7145b17093dcbcdb Mon Sep 17 00:00:00 2001 From: Shubham Arora Date: Sun, 29 Mar 2026 14:33:59 +0530 Subject: [PATCH] fix: use _validate_format for proper MIME type to Bedrock format mapping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Address Greptile review: naive media_type.split("/")[1] produced invalid Bedrock format names for complex MIME types (e.g. OOXML → docx, text/plain → txt, text/markdown → md). Now reuses BedrockImageProcessor._validate_format which handles all MIME types correctly via mimetypes + fallback. Also fixes test assertions to expect correct Bedrock format values and adds text/plain and text/markdown test cases. Co-Authored-By: Claude Opus 4.6 (1M context) --- litellm/litellm_core_utils/prompt_templates/factory.py | 4 +++- .../test_litellm_core_utils_prompt_templates_factory.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.py index 31612b8e78d..4990c7081b7 100644 --- a/litellm/litellm_core_utils/prompt_templates/factory.py +++ b/litellm/litellm_core_utils/prompt_templates/factory.py @@ -4741,7 +4741,9 @@ class BedrockConverseMessagesProcessor: source = element["source"] media_type: str = source["media_type"] data: str = source["data"] - doc_format = media_type.split("/")[1] + doc_format = BedrockImageProcessor._validate_format( + mime_type=media_type, image_format=media_type.split("/")[1] + ) # Deterministic name using the same hashing pattern as _create_bedrock_block HASH_SAMPLE_BYTES = 64 * 1024 diff --git a/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py b/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py index d6005f25da9..462d697e0a3 100644 --- a/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py +++ b/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py @@ -2444,9 +2444,11 @@ def test_bedrock_converse_messages_pt_document_various_formats(): ("application/pdf", "pdf"), ("text/csv", "csv"), ("text/html", "html"), + ("text/plain", "txt"), + ("text/markdown", "md"), ( "application/vnd.openxmlformats-officedocument.wordprocessingml.document", - "vnd.openxmlformats-officedocument.wordprocessingml.document", + "docx", ), ]