{"record":{"id":"e9ae15aefefd9d2c","repo":"spring-projects/spring-ai","slug":"unsupported-image-format","errorCode":null,"errorMessage":"Unsupported image format: ","messagePattern":"Unsupported image format: ","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-bedrock-converse/src/main/java/org/springframework/ai/bedrock/converse/api/BedrockMediaFormat.java","lineNumber":120,"sourceCode":"\t\treturn DOCUMENT_MAP.containsKey(mimeType);\n\t}\n\n\tpublic static DocumentFormat getDocumentFormat(MimeType mimeType) {\n\t\tDocumentFormat format = DOCUMENT_MAP.get(mimeType);\n\t\tif (format == null) {\n\t\t\tthrow new IllegalArgumentException(\"Unsupported document format: \" + mimeType);\n\t\t}\n\t\treturn format;\n\t}\n\n\tpublic static Boolean isSupportedImageFormat(MimeType mimeType) {\n\t\treturn IMAGE_MAP.containsKey(mimeType);\n\t}\n\n\tpublic static ImageFormat getImageFormat(MimeType mimeType) {\n\t\tImageFormat format = IMAGE_MAP.get(mimeType);\n\t\tif (format == null) {\n\t\t\tthrow new IllegalArgumentException(\"Unsupported image format: \" + mimeType);\n\t\t}\n\t\treturn format;\n\t}\n\n\tpublic static Boolean isSupportedVideoFormat(MimeType mimeType) {\n\t\treturn VIDEO_MAP.containsKey(mimeType);\n\t}\n\n\tpublic static VideoFormat getVideoFormat(MimeType mimeType) {\n\t\tVideoFormat format = VIDEO_MAP.get(mimeType);\n\t\tif (format == null) {\n\t\t\tthrow new IllegalArgumentException(\"Unsupported video format: \" + mimeType);\n\t\t}\n\t\treturn format;\n\t}\n\n}\n","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-bedrock-converse/src/main/java/org/springframework/ai/bedrock/converse/api/BedrockMediaFormat.java#L102-L138","documentation":"BedrockMediaFormat.getImageFormat() looks up the spring MimeMimeType in IMAGE_MAP, which maps MimeTypes to Bedrock Converse ImageFormat values. When the mime type has no entry, an IllegalArgumentException is thrown meaning Bedrock Converse does not support this image format. Only Bedrock-supported formats are mapped.","triggerScenarios":"Calling getFormatAsString/getImageFormat with an image MimeType not in IMAGE_MAP, e.g. image/tiff, image/bmp, image/webp, or a null/blank mediaType on a Media object passed into a Bedrock Converse ChatModel prompt.","commonSituations":"Passing a Media with a filename-derived mime type that Bedrock rejects; users assuming all common image types are supported; Media built without an explicit mime type.","solutions":["Convert the media to a Bedrock-supported format (png, jpeg, gif, webp) and set its MimeType accordingly.","Check IMAGE_MAP for supported types before sending (use isSupportedImageFormat).","Verify the Media object's mimeType field is populated, not null or empty.","Switch model or API if the unsupported format is required."],"exampleFix":"// before\nnew Media(MimeTypeUtils.parseMimeType(\"image/tiff\"), tiffResource);\n// after\nnew Media(MimeTypeUtils.parseMimeType(\"image/png\"), pngResource);","handlingStrategy":"validation","validationCode":"if (!BedrockMediaFormat.isSupportedImageFormat(media.getMimeType())) {\n    throw new IllegalArgumentException(\"Image format not supported by Bedrock: \" + media.getMimeType());\n}","typeGuard":"boolean isSupportedImage(MimeType mt) {\n    return mt != null && BedrockMediaFormat.isSupportedImageFormat(mt);\n}","tryCatchPattern":"try {\n    String fmt = BedrockMediaFormat.getFormatAsString(media);\n} catch (IllegalArgumentException e) {\n    // log and skip or convert media to a supported format\n}","preventionTips":["Always set an explicit supported MimeType on Media objects","Call isSupportedImageFormat before building prompts","Convert non-supported images to png/jpeg upstream"],"tags":["bedrock","image","unsupported-format","validation"],"backgroundTag":"unsupported-enum-value","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}