[fix] Clarify unsupported-modality error messages#3792
Merged
tomaarsen merged 2 commits intoJun 12, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves modality-validation error reporting by centralizing the unsupported-modality messaging logic in a shared helper and expanding tests to cover mixed, combined, and chat-style message inputs. It aims to ensure users see errors that reflect what they actually passed (rather than internal “message” inference artifacts).
Changes:
- Added
raise_unsupported_modality_error()insentence_transformers/base/modality.pyand wired it into bothBaseModel.preprocessandTransformer.preprocess. - Updated and expanded tests to validate clearer, scenario-specific error messages for unsupported, mixed, combined, and explicit chat-style inputs.
- Adjusted static embedding modality tests to expect the new mixed-batch wording.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
sentence_transformers/base/modality.py |
Introduces shared helper to generate tailored unsupported-modality errors. |
sentence_transformers/base/model.py |
Switches BaseModel.preprocess to use the shared helper for modality errors. |
sentence_transformers/base/modules/transformer.py |
Switches Transformer.preprocess to use the shared helper for modality errors. |
tests/base/test_model.py |
Replaces prior targeted modality tests with a parametrized matrix covering many error scenarios. |
tests/base/modules/test_transformer.py |
Adds coverage ensuring Transformer uses the shared helper and emits expected wording. |
tests/sentence_transformer/modules/test_static_embedding.py |
Updates expected error message for mixed-modality batch handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #3789
Hello!
Pull Request overview
raise_unsupported_modality_errorhelper acrossBaseModelandTransformerDetails
When inputs don't match what a model supports, the errors were confusing. Because a batch that mixes modalities collapses to the internal
"message"modality (the format we use to combine modalities into one input), passing e.g. a list of images and texts to CLIP raisedModality 'message' is not supported, even though the user never passed a message. That's the confusion reported in #3722. A single combined{"text": ..., "image": ...}input was worse: on a model that supports both modalities individually it raisedModality 'image+text' is not supported. Supported modalities: text, image, contradicting itself.I've reworked the validation to re-inspect the per-sample modalities on the error path and emit guidance tailored to the actual situation: explicit chat-style
messageinputs, a mixed batch containing a genuinely unsupported modality (now named explicitly), a mixed batch the model could encode one modality at a time (so the message says to do exactly that), and a single combined input whose parts are each supported but can't be fused withoutmessagesupport. All of this now lives in oneraise_unsupported_modality_errorhelper inmodality.py, shared byBaseModel.preprocessandTransformer.preprocessso both raise the same accurate message.This supersedes #3789, which clarified only the mixed-modality batch case. This version should cover every unsupported-modality scenario and unifies the two code paths. I also expanded the tests into a parametrized matrix that exercises the real inference path for each case, with guards against misleading wording (e.g. never claiming a modality is unsupported when every part is actually supported).