{"record":{"id":"72743c190fa7630e","repo":"spring-projects/spring-ai","slug":"unsupported-mimetype-s","errorCode":null,"errorMessage":"Unsupported MimeType: %s","messagePattern":"Unsupported MimeType: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-model/src/main/java/org/springframework/ai/embedding/EmbeddingResultMetadata.java","lineNumber":120,"sourceCode":"\n\t\t\tif (mimeType == null) {\n\t\t\t\treturn ModalityType.TEXT;\n\t\t\t}\n\n\t\t\tif (mimeType.isCompatibleWith(IMAGE_MIME_TYPE)) {\n\t\t\t\treturn ModalityType.IMAGE;\n\t\t\t}\n\t\t\telse if (mimeType.isCompatibleWith(AUDIO_MIME_TYPE)) {\n\t\t\t\treturn ModalityType.AUDIO;\n\t\t\t}\n\t\t\telse if (mimeType.isCompatibleWith(VIDEO_MIME_TYPE)) {\n\t\t\t\treturn ModalityType.VIDEO;\n\t\t\t}\n\t\t\telse if (mimeType.isCompatibleWith(TEXT_MIME_TYPE)) {\n\t\t\t\treturn ModalityType.TEXT;\n\t\t\t}\n\n\t\t\tthrow new IllegalArgumentException(\"Unsupported MimeType: \" + mimeType);\n\t\t}\n\n\t}\n\n}\n","sourceCodeStart":102,"sourceCodeEnd":126,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/spring-ai-model/src/main/java/org/springframework/ai/embedding/EmbeddingResultMetadata.java#L102-L126","documentation":"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.","triggerScenarios":"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.","commonSituations":"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'.","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"],"exampleFix":"// before\nmetadata.setModalityType(EmbeddingResultMetadata.getModalityType(MimeTypeUtils.parseMimeType(\"application/pdf\")));\n// after\nMimeType mime = MimeTypeUtils.parseMimeType(\"text/plain\"); // or map pdf -> text upstream\nif (mime.isCompatibleWith(EmbeddingResultMetadata.TEXT_MIME_TYPE)) {\n    metadata.setModalityType(EmbeddingResultMetadata.getModalityType(mime));\n}","handlingStrategy":"validation","validationCode":"MimeType mime = MimeTypeUtils.parseMimeType(raw);\nList<MimeType> supported = List.of(EmbeddingResultMetadata.AUDIO_MIME_TYPE, EmbeddingResultMetadata.IMAGE_MIME_TYPE, EmbeddingResultMetadata.VIDEO_MIME_TYPE, EmbeddingResultMetadata.TEXT_MIME_TYPE);\nif (supported.stream().noneMatch(mime::isCompatibleWith)) {\n    throw new IllegalArgumentException(\"MIME type not supported for embeddings: \" + mime);\n}","typeGuard":"boolean isSupportedEmbeddingMime(MimeType m) {\n    return m.isCompatibleWith(EmbeddingResultMetadata.TEXT_MIME_TYPE)\n        || m.isCompatibleWith(EmbeddingResultMetadata.IMAGE_MIME_TYPE)\n        || m.isCompatibleWith(EmbeddingResultMetadata.AUDIO_MIME_TYPE)\n        || m.isCompatibleWith(EmbeddingResultMetadata.VIDEO_MIME_TYPE);\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["mime-type","embedding","illegal-argument","unsupported-type"],"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-14T05:17:10.506Z"}