{"record":{"id":"8fb6a56cf7f4366c","repo":"langchain-ai/deepagents","slug":"media-file-type-detected-r-does-not-match-reques","errorCode":null,"errorMessage":"media file type {detected!r} does not match requested type {media.media_type!r}","messagePattern":"media file type (.+?) does not match requested type (.+?)","errorType":"exception","errorClass":"ChannelMediaError","httpStatus":null,"severity":"error","filePath":"libs/talon/deepagents_talon/channels/base.py","lineNumber":271,"sourceCode":"        ChannelMediaError: If the file is missing, unsupported, or too large.\n    \"\"\"\n    try:\n        path = (\n            resolve_bounded_media_path(media.path, root, require_relative=False)\n            if root is not None\n            else media.path.expanduser()\n        )\n    except ValueError as exc:\n        msg = str(exc)\n        raise ChannelMediaError(msg) from exc\n    if not path.is_file():\n        msg = f\"media file does not exist: {path}\"\n        raise ChannelMediaError(msg)\n\n    detected = _media_type(path)\n    if detected != media.media_type:\n        msg = f\"media file type {detected!r} does not match requested type {media.media_type!r}\"\n        raise ChannelMediaError(msg)\n\n    return _validate_media_size(media, path=path, max_bytes=max_bytes)\n\n\ndef message_with_media_paths(\n    message: ChannelMessage,\n    *,\n    media_paths: Sequence[str],\n    mime_types: Sequence[str] = (),\n    has_media: bool | None = None,\n) -> ChannelMessage:\n    \"\"\"Return `message` with normalized inbound-media path metadata.\n\n    Args:\n        message: Original channel message.\n        media_paths: Local media paths associated with the message.\n        mime_types: MIME types aligned with `media_paths`.\n        has_media: Optional provider-reported media presence. When omitted, this","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/talon/deepagents_talon/channels/base.py#L253-L289","documentation":"`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.","triggerScenarios":"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).","commonSituations":"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`.","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."],"exampleFix":"# before\nChannelMedia(path=Path('report.pdf'), media_type='image')\n\n# after\nChannelMedia(path=Path('report.pdf'), media_type='document')","handlingStrategy":"validation","validationCode":"from deepagents_talon.channels.base import _media_type\npath = Path(media.path)\nif _media_type(path) != media.media_type:\n    raise ValueError(f'{path} is {_media_type(path)}, not {media.media_type}')","typeGuard":null,"tryCatchPattern":"try:\n    await channel.send_media(media)\nexcept ChannelMediaError as exc:\n    if 'does not match requested type' in str(exc):\n        await channel.send_text(f'Attachment type mismatch: {exc}')\n    else:\n        raise","preventionTips":["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."],"tags":["media","validation","type-mismatch"],"backgroundTag":"media-type-mismatch","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}