Skip to content

fix(agentic-ai): Normalize AI agent document content type by lowercasing and trimming#7010

Merged
nikonovd merged 3 commits into
mainfrom
agentic-ai/bugfix/content-type-normalization
Apr 22, 2026
Merged

fix(agentic-ai): Normalize AI agent document content type by lowercasing and trimming#7010
nikonovd merged 3 commits into
mainfrom
agentic-ai/bugfix/content-type-normalization

Conversation

@nikonovd
Copy link
Copy Markdown
Contributor

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

  • Backport labels are added if these code changes should be backported. No backport label is added to the latest
    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.
    • or backport release-8.8.7: for changes that should be included in the specific release 8.8.7, and this
      release 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.
  • Tests/Integration tests for the changes have been added if applicable.
  • If the change requires a documentation update, it has been added to the appropriate section in the documentation.

@nikonovd nikonovd self-assigned this Apr 21, 2026
Copilot AI review requested due to automatic review settings April 21, 2026 14:46
@nikonovd nikonovd requested a review from a team as a code owner April 21, 2026 14:46
@nikonovd nikonovd requested a review from a team as a code owner April 21, 2026 14:46
@nikonovd nikonovd requested review from ztefanie and removed request for ztefanie April 21, 2026 14:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-Type values before parsing/usage in DocumentToContentConverterImpl.
  • 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.

Comment on lines 73 to 78
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)
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
.satisfies(
imageContent -> {
assertThat(imageContent.image().mimeType())
.isEqualTo(contentType.toLowerCase(Locale.ROOT).trim());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 Should we compare to the actual expected output image/png instead of repeating the logic here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid point, i applied the suggestion 👍

@nikonovd nikonovd added this pull request to the merge queue Apr 22, 2026
Merged via the queue into main with commit 0c92477 Apr 22, 2026
51 of 52 checks passed
@nikonovd nikonovd deleted the agentic-ai/bugfix/content-type-normalization branch April 22, 2026 07:44
@team-connectors-int-automation
Copy link
Copy Markdown
Contributor

@team-connectors-int-automation
Copy link
Copy Markdown
Contributor

nikonovd added a commit that referenced this pull request Apr 22, 2026
…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>
nikonovd added a commit that referenced this pull request Apr 22, 2026
…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>
@github-actions
Copy link
Copy Markdown
Contributor

🎉 This pull request has been included in release 8.9.2!

Thank you for your contribution! 🚀

@github-actions github-actions Bot added the version:8.9.2 Released in version 8.9.2 label Apr 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

🎉 This pull request has been included in release 8.8.11!

Thank you for your contribution! 🚀

@github-actions github-actions Bot added the version:8.8.11 Released in version 8.8.11 label May 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🎉 This pull request has been included in release 8.10.0-alpha1!

Thank you for your contribution! 🚀

@github-actions github-actions Bot added the version:8.10.0-alpha1 Released in version 8.10.0-alpha1 label May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agentic-ai backport stable/8.8 backport stable/8.9 version:8.8.11 Released in version 8.8.11 version:8.9.2 Released in version 8.9.2 version:8.10.0-alpha1 Released in version 8.10.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AI agent is failing to upload images with non-lowercased mime types to OpenAI

3 participants