fix: use _validate_format for proper MIME type to Bedrock format mapping

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) <noreply@anthropic.com>
This commit is contained in:
Shubham Arora 2026-03-29 14:33:59 +05:30
parent 810351f3e4
commit bc29b90c1d
2 changed files with 6 additions and 2 deletions

View file

@ -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

View file

@ -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",
),
]