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

  1. Call BedrockMediaFormat.isSupportedDocumentFormat(mimeType) before sending and fall back otherwise.
  2. Use one of the supported document MIME types (application/pdf, text/plain, text/html, text/csv, application/msword, etc.).
  3. Convert unsupported documents (e.g. JSON) to txt/pdf before attaching.
  4. 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

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


AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11). Data as JSON: /api/errors/de04a0a78bb0a244. Report an issue: GitHub.