diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.py index f6004616712..4f2952802f2 100644 --- a/litellm/litellm_core_utils/prompt_templates/factory.py +++ b/litellm/litellm_core_utils/prompt_templates/factory.py @@ -3602,6 +3602,8 @@ class BedrockImageProcessor: ######################################################### # Check if image_format is an image or video ######################################################### + format_aliases = {"jpg": "jpeg", "mpg": "mpeg"} + image_format = format_aliases.get(image_format, image_format) if image_format not in supported_image_and_video_formats: raise ValueError( f"Unsupported image format: {image_format}. Supported formats: {supported_image_and_video_formats}" 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 988941d1d91..8a2460dbfd8 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 @@ -134,7 +134,6 @@ def test_bedrock_validate_format_image_or_video(): "webm", "flv", "mpeg", - "mpg", "wmv", "3gp", ] @@ -142,6 +141,10 @@ def test_bedrock_validate_format_image_or_video(): result = BedrockImageProcessor._validate_format(f"video/{format}", format) assert result == format, f"Expected {format}, got {result}" + # 'mpg' is aliased to 'mpeg' + result = BedrockImageProcessor._validate_format("video/mpg", "mpg") + assert result == "mpeg", f"Expected 'mpeg', got '{result}'" + # Test valid document formats valid_document_formats = { "application/pdf": "pdf", @@ -155,6 +158,38 @@ def test_bedrock_validate_format_image_or_video(): assert result == expected, f"Expected {expected}, got {result}" +def test_bedrock_validate_format_resolves_common_aliases(): + """ + Test that _validate_format resolves common format aliases like + 'jpg' -> 'jpeg' and 'mpg' -> 'mpeg' instead of raising ValueError. + + These aliases are standard equivalents (JPEG files commonly use .jpg + extension, MPEG videos commonly use .mpg extension) but were previously + rejected because only the canonical names appeared in the supported + formats list. + + Regression test for: https://github.com/BerriAI/litellm/issues/XXXXX + """ + # 'jpg' should be resolved to 'jpeg' + result_jpg = BedrockImageProcessor._validate_format("image/jpg", "jpg") + assert result_jpg == "jpeg", f"Expected 'jpeg', got '{result_jpg}'" + + # 'mpg' should be resolved to 'mpeg' + result_mpg = BedrockImageProcessor._validate_format("video/mpg", "mpg") + assert result_mpg == "mpeg", f"Expected 'mpeg', got '{result_mpg}'" + + # Canonical names should still work unchanged + result_jpeg = BedrockImageProcessor._validate_format("image/jpeg", "jpeg") + assert result_jpeg == "jpeg", f"Expected 'jpeg', got '{result_jpeg}'" + + result_mpeg = BedrockImageProcessor._validate_format("video/mpeg", "mpeg") + assert result_mpeg == "mpeg", f"Expected 'mpeg', got '{result_mpeg}'" + + # Unsupported formats should still raise ValueError + with pytest.raises(ValueError, match="Unsupported image format"): + BedrockImageProcessor._validate_format("image/bmp", "bmp") + + def test_bedrock_get_document_format_fallback_mimes(): """ Test the _get_document_format method with fallback MIME types for DOCX and XLSX.