Fix media type matching in unions to use file extension heuristics#2894
Merged
antoniosarosi merged 2 commits intocanaryfrom Dec 31, 2025
Merged
Fix media type matching in unions to use file extension heuristics#2894antoniosarosi merged 2 commits intocanaryfrom
antoniosarosi merged 2 commits intocanaryfrom
Conversation
When coercing a value like `{ file: "document.pdf" }` to a union type
like `(image | pdf)`, the code previously matched the first variant
(`image`) regardless of the file extension, resulting in invalid MIME
types like "image/pdf".
This change adds extension-based matching for media types in unions:
- Extract file extension from `{ file: "..." }` or `{ url: "..." }`
- Match against the appropriate media type based on extension
- Fall back to original first-match behavior if no extension match
Also adds strict media type matching when coercing already-coerced
BamlValue::Media to ensure the media_type field matches the target,
with fallback cases for backwards compatibility.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
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.
Summary
When coercing a value like
{ file: "document.pdf" }to a union type like(image | pdf), the code previously matched the first variant (image) regardless of the file extension, resulting in invalid MIME types likeimage/pdf.This change:
.pdf,.png,.mp3, etc.){ file: "..." }and{ url: "..." }forms, including URLs with query paramsBamlValue::Mediawith fallback for backwards compatibilityFix #2782
Test plan
(image | pdf)[]union now correctly identifies PDF files[<application_placeholder base64>]instead of[<image_placeholder base64>]