Skip to content

Conversation

@Yash3561
Copy link

@Yash3561 Yash3561 commented Jan 16, 2026

Why are these changes needed?

This PR fixes a critical bug in UserMessage deserialization where mixed-media payloads (containing both str and Image objects) cause a TypeError during JSON deserialization (Issue #7170).

The Root Cause:
In Pydantic V2, a TypeError raised within a custom validator (specifically in Image.__get_pydantic_core_schema__) is interpreted as a terminal failure during Union resolution. This prevents the resolver from attempting subsequent branches in a Union or List[Union[...]].

The Fix:
By refactoring the Image validator to raise a ValueError instead of a TypeError when a non-dict/non-Image type is encountered, we enable the Pydantic C-engine to treat the current branch as a mismatch rather than a fatal error. This allows the resolver to successfully fall back to the str branch, enabling full support for multimodal message schemas in parity with OpenAI and Gemini API standards.

Related issue number

Closes #7170

Checks

  • I've included any doc changes needed for https://microsoft.github.io/autogen/. (No doc changes required for this logic fix).
  • I've added tests (if relevant) corresponding to the changes introduced in this PR.
  • I've made sure all auto checks have passed.

@Yash3561
Copy link
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

when UserMessage have both string and Image data,JSON deserialization cause error

1 participant