{"record":{"id":"de04a0a78bb0a244","repo":"spring-projects/spring-ai","slug":"unsupported-document-format","errorCode":null,"errorMessage":"Unsupported document format: ","messagePattern":"Unsupported document 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":108,"sourceCode":"\t\t\treturn getDocumentFormat(mimeType).toString();\n\t\t}\n\t\telse if (isSupportedImageFormat(mimeType)) {\n\t\t\treturn getImageFormat(mimeType).toString();\n\t\t}\n\t\telse if (isSupportedVideoFormat(mimeType)) {\n\t\t\treturn getVideoFormat(mimeType).toString();\n\t\t}\n\t\tthrow new IllegalArgumentException(\"Unsupported media format: \" + mimeType);\n\t}\n\n\tpublic static Boolean isSupportedDocumentFormat(MimeType mimeType) {\n\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);","sourceCodeStart":90,"sourceCodeEnd":126,"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#L90-L126","documentation":"BedrockMediaFormat.getDocumentFormat looks up a DocumentFormat enum in DOCUMENT_MAP and throws this IllegalArgumentException when the MimeType is not a supported Bedrock document type. Bedrock documents support only pdf, csv, doc, docx, xls, xlsx, html, txt, md.","triggerScenarios":"Calling getDocumentFormat (directly, or indirectly via getFormatAsString/media handling) with a non-document MimeType such as image/png, application/json, text/xml, or an unsupported document subtype.","commonSituations":"Sending JSON/XML attachments as documents; using image MimeType with document-related code paths; passing Markdown variants like text/markdown when the map expects text/markdown per the library version.","solutions":["Call BedrockMediaFormat.isSupportedDocumentFormat(mimeType) before sending and fall back otherwise.","Use one of the supported document MIME types (application/pdf, text/plain, text/html, text/csv, application/msword, etc.).","Convert unsupported documents (e.g. JSON) to txt/pdf before attaching.","Check the DOCUMENT_MAP in your library version for the exact accepted MimeType constants."],"exampleFix":"// before\nnew Media(new MimeType(\"application\", \"json\"), jsonBytes);\n// after\nnew Media(new MimeType(\"text\", \"plain\"),\n    jsonBytes); // attach JSON as plain text document","handlingStrategy":"validation","validationCode":"if (!Boolean.TRUE.equals(BedrockMediaFormat.isSupportedDocumentFormat(mimeType))) {\n    throw new IllegalArgumentException(\"Not a Bedrock-supported document type: \" + mimeType);\n}","typeGuard":"boolean isBedrockDocument(MimeType mt) {\n    return Boolean.TRUE.equals(BedrockMediaFormat.isSupportedDocumentFormat(mt));\n}","tryCatchPattern":"try {\n    DocumentFormat f = BedrockMediaFormat.getDocumentFormat(mt);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Unsupported document format\")) {\n        // convert document to PDF/txt or reject the upload\n    } else throw e;\n}","preventionTips":["Whitelist pdf/csv/doc/docx/xls/xlsx/html/txt/md at upload time","Do not send JSON/XML as documents — wrap as text/plain or embed in prompt","Use BedrockMediaFormat.isSupportedDocumentFormat as a pre-check","Keep a conversion step (e.g. to PDF) for arbitrary office files"],"tags":["document","mime-type","unsupported-format","bedrock"],"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"}