langchain-ai/deepagents · error · ChannelMediaError
media file type {detected!r} does not match requested type {
Error message
media file type {detected!r} does not match requested type {media.media_type!r} What it means
`validate_media` sniffs the file's actual content type with `_media_type` (mimetypes-based detection) and compares it to the `media_type` requested on the `ChannelMedia`. A mismatch raises `ChannelMediaError`, guarding against sending mislabeled attachments that a channel would caption or process incorrectly.
Source
Thrown at libs/talon/deepagents_talon/channels/base.py:271
ChannelMediaError: If the file is missing, unsupported, or too large.
"""
try:
path = (
resolve_bounded_media_path(media.path, root, require_relative=False)
if root is not None
else media.path.expanduser()
)
except ValueError as exc:
msg = str(exc)
raise ChannelMediaError(msg) from exc
if not path.is_file():
msg = f"media file does not exist: {path}"
raise ChannelMediaError(msg)
detected = _media_type(path)
if detected != media.media_type:
msg = f"media file type {detected!r} does not match requested type {media.media_type!r}"
raise ChannelMediaError(msg)
return _validate_media_size(media, path=path, max_bytes=max_bytes)
def message_with_media_paths(
message: ChannelMessage,
*,
media_paths: Sequence[str],
mime_types: Sequence[str] = (),
has_media: bool | None = None,
) -> ChannelMessage:
"""Return `message` with normalized inbound-media path metadata.
Args:
message: Original channel message.
media_paths: Local media paths associated with the message.
mime_types: MIME types aligned with `media_paths`.
has_media: Optional provider-reported media presence. When omitted, thisView on GitHub (pinned to a1af029e6e)
Solutions
- Set `media_type` to match the actual file, or fix the file's extension so detection matches.
- Inspect the detected type in the error message and correct the `ChannelMedia` construction.
- Catch `ChannelMediaError` and surface the mismatch to the caller.
Example fix
# before
ChannelMedia(path=Path('report.pdf'), media_type='image')
# after
ChannelMedia(path=Path('report.pdf'), media_type='document') Defensive patterns
Strategy: validation
Validate before calling
from deepagents_talon.channels.base import _media_type
path = Path(media.path)
if _media_type(path) != media.media_type:
raise ValueError(f'{path} is {_media_type(path)}, not {media.media_type}') Try / catch
try:
await channel.send_media(media)
except ChannelMediaError as exc:
if 'does not match requested type' in str(exc):
await channel.send_text(f'Attachment type mismatch: {exc}')
else:
raise Prevention
- Derive `media_type` from the file's detected type instead of hardcoding it.
- Fix file extensions at generation time so detection is accurate.
- Add a unit check when constructing ChannelMedia in adapters.
When it happens
Trigger: Calling `validate_media`/`send_media` where `media.media_type` (e.g. 'image') does not match the type detected from the file extension/content (e.g. the file is actually a PDF or the extension is wrong).
Common situations: Renaming a file to `.png` when it is a JPEG is fine, but labeling a text file as 'image'; hardcoding `media_type='voice'` for a video; generated artifacts written with a generic extension like `.bin`.
Related errors
- Goal criteria request field {key} must be text.
- media file is too large: {size} bytes exceeds {max_bytes}
- {media.media_type} media is too large: {size} bytes exceeds
- unsupported media file type: {path}
- unsupported media mime type: {mime}
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/8fb6a56cf7f4366c.
Report an issue: GitHub.