Skip to content

Python: fix(ollama): reject non-image data content instead of sending it as an image - #8917

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
Leela0o5:fix/ollama-reject-non-image-data
Oct 1, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
Leela0o5:fix/ollama-reject-non-image-data

Conversation

@Leela0o5

Copy link
Copy Markdown
Contributor

Motivation & Context

OllamaChatClient checked that any data content in a user message was an image, then sent all data contents in Ollama's images field. A user message with an image plus a non-image attachment (e.g. a PDF) passed the check, and the PDF bytes were sent to Ollama as an image. Ollama's chat API has no document input, so this can never work and fails later with a confusing error.

Description & Review Guide

  • What are the major changes? The check in _format_user_message now requires every data content to be an image (any to all). Added a unit test with an image plus a PDF.
  • What is the impact of these changes? Mixed image/non-image messages now fail early with ChatClientInvalidRequestException, matching how a message with only non-image data is already handled. Image-only messages are unchanged.
  • What do you want reviewers to focus on? Whether rejecting (rather than dropping the non-image items with a warning) is the preferred behavior.

Related Issue

Fixes #8916

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Sep 30, 2026
@Leela0o5

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The validation change directly resolves the reported bug and includes focused regression coverage.

Review effort: Balanced
Findings: None

Merged via the queue into microsoft:main with commit 2f84b14 Oct 1, 2026
44 checks passed

This branch was previously deployed

1 inactive deployment
github-app-auth — 265530f6 Deployed Sep 30, 2026 by Leela0o5 via add_label #24136
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: OllamaChatClient sends non-image data content to Ollama as images

3 participants