spring-projects/spring-ai · error · IllegalArgumentException
Unsupported MimeType: %s
Error message
Unsupported MimeType: %s
What it means
EmbeddingResultMetadata.getModalityType() maps a Spring MimeType to an embedding ModalityType (AUDIO, IMAGE, VIDEO, TEXT). When the MimeType is not compatible with any of the known modality types, it throws this IllegalArgumentException. This guards the metadata from carrying an unclassifiable content type.
Source
Thrown at spring-ai-model/src/main/java/org/springframework/ai/embedding/EmbeddingResultMetadata.java:120
if (mimeType == null) {
return ModalityType.TEXT;
}
if (mimeType.isCompatibleWith(IMAGE_MIME_TYPE)) {
return ModalityType.IMAGE;
}
else if (mimeType.isCompatibleWith(AUDIO_MIME_TYPE)) {
return ModalityType.AUDIO;
}
else if (mimeType.isCompatibleWith(VIDEO_MIME_TYPE)) {
return ModalityType.VIDEO;
}
else if (mimeType.isCompatibleWith(TEXT_MIME_TYPE)) {
return ModalityType.TEXT;
}
throw new IllegalArgumentException("Unsupported MimeType: " + mimeType);
}
}
}
View on GitHub (pinned to 98a7beda4f)
Solutions
- Check the MimeType passed into the embedding pipeline and set it to one of the supported types: audio/*, image/*, video/*, or text/* compatible types
- Use MimeTypeUtils.parseMimeType with a correct MIME string and verify mimeType.isCompatibleWith() against the supported constants before calling
- If supporting a new modality, upgrade spring-ai to a version that maps that MIME type, or handle the mapping in your own code before metadata construction
Example fix
// before
metadata.setModalityType(EmbeddingResultMetadata.getModalityType(MimeTypeUtils.parseMimeType("application/pdf")));
// after
MimeType mime = MimeTypeUtils.parseMimeType("text/plain"); // or map pdf -> text upstream
if (mime.isCompatibleWith(EmbeddingResultMetadata.TEXT_MIME_TYPE)) {
metadata.setModalityType(EmbeddingResultMetadata.getModalityType(mime));
} Defensive patterns
Strategy: validation
Validate before calling
MimeType mime = MimeTypeUtils.parseMimeType(raw);
List<MimeType> supported = List.of(EmbeddingResultMetadata.AUDIO_MIME_TYPE, EmbeddingResultMetadata.IMAGE_MIME_TYPE, EmbeddingResultMetadata.VIDEO_MIME_TYPE, EmbeddingResultMetadata.TEXT_MIME_TYPE);
if (supported.stream().noneMatch(mime::isCompatibleWith)) {
throw new IllegalArgumentException("MIME type not supported for embeddings: " + mime);
} Type guard
boolean isSupportedEmbeddingMime(MimeType m) {
return m.isCompatibleWith(EmbeddingResultMetadata.TEXT_MIME_TYPE)
|| m.isCompatibleWith(EmbeddingResultMetadata.IMAGE_MIME_TYPE)
|| m.isCompatibleWith(EmbeddingResultMetadata.AUDIO_MIME_TYPE)
|| m.isCompatibleWith(EmbeddingResultMetadata.VIDEO_MIME_TYPE);
} Prevention
- Only assign standard audio/*, image/*, video/*, or text/* MIME types to embedded content
- Normalize custom MIME types to the closest supported category before embedding
- Add a pre-check with isCompatibleWith against the metadata constants before constructing embedding metadata
When it happens
Trigger: Calling getModalityType() with a MimeType that is not compatible with AUDIO_MIME_TYPE, IMAGE_MIME_TYPE, VIDEO_MIME_TYPE, or TEXT_MIME_TYPE, e.g. application/pdf or a custom/embedded MIME subtype passed through embedding metadata.
Common situations: Using an EmbeddingModel with document content whose MIME type was set incorrectly by a DocumentReader; passing a niche media type (e.g. font or model formats) to a multimodal embedding pipeline; typos in MIME type strings like 'text/json' instead of 'application/json'.
Related errors
- Unsupported list item type: {itemClassName}. Expected String
- No embedding input is provided - all texts are null or empty
- Unsupported image mime type: ${mimeType}
- Unsupported media type: ${mimeType}
- Unknown message type:
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/72743c190fa7630e.
Report an issue: GitHub.