spring-projects/spring-ai · error · java.lang.IllegalArgumentException
Unsupported document format:
Error message
Unsupported document format:
What it means
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.
Source
Thrown at models/spring-ai-bedrock-converse/src/main/java/org/springframework/ai/bedrock/converse/api/BedrockMediaFormat.java:108
return getDocumentFormat(mimeType).toString();
}
else if (isSupportedImageFormat(mimeType)) {
return getImageFormat(mimeType).toString();
}
else if (isSupportedVideoFormat(mimeType)) {
return getVideoFormat(mimeType).toString();
}
throw new IllegalArgumentException("Unsupported media format: " + mimeType);
}
public static Boolean isSupportedDocumentFormat(MimeType mimeType) {
return DOCUMENT_MAP.containsKey(mimeType);
}
public static DocumentFormat getDocumentFormat(MimeType mimeType) {
DocumentFormat format = DOCUMENT_MAP.get(mimeType);
if (format == null) {
throw new IllegalArgumentException("Unsupported document format: " + mimeType);
}
return format;
}
public static Boolean isSupportedImageFormat(MimeType mimeType) {
return IMAGE_MAP.containsKey(mimeType);
}
public static ImageFormat getImageFormat(MimeType mimeType) {
ImageFormat format = IMAGE_MAP.get(mimeType);
if (format == null) {
throw new IllegalArgumentException("Unsupported image format: " + mimeType);
}
return format;
}
public static Boolean isSupportedVideoFormat(MimeType mimeType) {
return VIDEO_MAP.containsKey(mimeType);View on GitHub (pinned to 98a7beda4f)
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.
Example fix
// before
new Media(new MimeType("application", "json"), jsonBytes);
// after
new Media(new MimeType("text", "plain"),
jsonBytes); // attach JSON as plain text document Defensive patterns
Strategy: validation
Validate before calling
if (!Boolean.TRUE.equals(BedrockMediaFormat.isSupportedDocumentFormat(mimeType))) {
throw new IllegalArgumentException("Not a Bedrock-supported document type: " + mimeType);
} Type guard
boolean isBedrockDocument(MimeType mt) {
return Boolean.TRUE.equals(BedrockMediaFormat.isSupportedDocumentFormat(mt));
} Try / catch
try {
DocumentFormat f = BedrockMediaFormat.getDocumentFormat(mt);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("Unsupported document format")) {
// convert document to PDF/txt or reject the upload
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unsupported media format:
- Unsupported media format:
- Unsupported image format:
- Unsupported video format:
- Unsupported value type:
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/de04a0a78bb0a244.
Report an issue: GitHub.