fix(agentic-ai): Normalize AI agent document content type by lowercasing and trimming#7010
Conversation
There was a problem hiding this comment.
Pull request overview
Normalizes MIME types for AI agent Document inputs so providers like OpenAI don’t reject image uploads when the incoming Content-Type uses mixed/upper casing and/or surrounding whitespace.
Changes:
- Lowercase document
Content-Typevalues before parsing/usage inDocumentToContentConverterImpl. - Add unit coverage ensuring image MIME types are emitted in normalized (lowercased/trimmed) form.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| connectors/agentic-ai/src/main/java/io/camunda/connector/agenticai/aiagent/framework/langchain4j/document/DocumentToContentConverterImpl.java | Normalizes Content-Type casing before converting a Camunda Document into LangChain4j content. |
| connectors/agentic-ai/src/test/java/io/camunda/connector/agenticai/aiagent/framework/langchain4j/document/DocumentToContentConverterTest.java | Adds a parameterized test covering mixed-case and whitespace-padded image MIME types. |
| private static ContentType getContentType(Document camundaDocument) { | ||
| return Optional.ofNullable(camundaDocument.metadata()) | ||
| .map(DocumentMetadata::getContentType) | ||
| .filter(StringUtils::isNotBlank) | ||
| .map(s -> s.toLowerCase(Locale.ROOT)) | ||
| .map(ContentType::parse) |
There was a problem hiding this comment.
getContentType(...) lowercases the content-type string but does not explicitly trim it. This means the advertised normalization ("lowercasing and trimming") currently relies on ContentType.parse(...) to ignore leading/trailing whitespace. Consider adding an explicit trim() (ideally before lowercasing/parsing) so normalization is guaranteed and independent of the parser's whitespace tolerance.
| .satisfies( | ||
| imageContent -> { | ||
| assertThat(imageContent.image().mimeType()) | ||
| .isEqualTo(contentType.toLowerCase(Locale.ROOT).trim()); |
There was a problem hiding this comment.
🔧 Should we compare to the actual expected output image/png instead of repeating the logic here?
There was a problem hiding this comment.
Valid point, i applied the suggestion 👍
|
Successfully created backport PR for |
|
Successfully created backport PR for |
…ing and trimming (#7010) (#7017) * fix: Normalize AI agent document content type by lowercasing * test: Verify trimming is also applied * test: assert on image/png instead of repeating logic (cherry picked from commit 0c92477) Co-authored-by: Dmitri Nikonov <6192565+nikonovd@users.noreply.github.com>
…ing and trimming (#7010) (#7016) * fix: Normalize AI agent document content type by lowercasing * test: Verify trimming is also applied * test: assert on image/png instead of repeating logic (cherry picked from commit 0c92477) Co-authored-by: Dmitri Nikonov <6192565+nikonovd@users.noreply.github.com>
|
🎉 This pull request has been included in release Thank you for your contribution! 🚀 |
|
🎉 This pull request has been included in release Thank you for your contribution! 🚀 |
|
🎉 This pull request has been included in release Thank you for your contribution! 🚀 |
Description
Some providers, like OpenAI do not allow content types for e.g. images to be uppercased, i.e.
IMAGE/PNG.Thus, the content type is normalized for AI agent document inputs by lowercasing and trimming them.
Related issues
closes #7009
Checklist
release, as this branch will be rebased onto main before the next release. Example backport labels:
backport stable/8.8: for changes that should be included in the next 8.8.x release.backport release-8.8.7: for changes that should be included in the specific release 8.8.7, and thisrelease has already been created. The release branch will be merged back into stable/8.8 later, so the change
will be included in future 8.8.x releases as well.