{"record":{"id":"bc7b1362ce55cb73","repo":"langchain-ai/deepagents","slug":"media-media-type-media-is-too-large-size-byte","errorCode":null,"errorMessage":"{media.media_type} media is too large: {size} bytes exceeds {max_bytes}","messagePattern":"(.+?) media is too large: (.+?) bytes exceeds (.+?)","errorType":"exception","errorClass":"ChannelMediaError","httpStatus":null,"severity":"error","filePath":"libs/talon/deepagents_talon/channels/base.py","lineNumber":435,"sourceCode":"\n    Returns:\n        The string if it is a non-empty ``str``, otherwise ``None``.\n    \"\"\"\n    return value if isinstance(value, str) and value else None\n\n\ndef _validate_media_size(\n    media: ChannelMedia,\n    *,\n    path: Path,\n    max_bytes: int | None = None,\n) -> ChannelMedia:\n    if max_bytes is None:\n        return ChannelMedia(path=path, media_type=media.media_type, caption=media.caption)\n    size = path.stat().st_size\n    if size > max_bytes:\n        msg = f\"{media.media_type} media is too large: {size} bytes exceeds {max_bytes}\"\n        raise ChannelMediaError(msg)\n\n    return ChannelMedia(path=path, media_type=media.media_type, caption=media.caption)\n\n\ndef _is_self_message(message: ChannelMessage, operator_ids: frozenset[str]) -> bool:\n    if message.metadata.get(\"from_self\") is True:\n        return True\n    return message.sender_id is not None and message.sender_id in operator_ids\n\n\ndef _matches_text(text: str, patterns: tuple[str, ...]) -> bool:\n    return any(fnmatch.fnmatchcase(text, pattern) for pattern in patterns)\n\n\ndef _exposure_mode(value: str, *, provider: str) -> ExposureMode:\n    try:\n        return ExposureMode(value)\n    except ValueError as error:","sourceCodeStart":417,"sourceCodeEnd":453,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/talon/deepagents_talon/channels/base.py#L417-L453","documentation":"`_validate_media_size` is the private final step of `validate_media`; when a per-media `max_bytes` is configured and the file's size exceeds it, it raises `ChannelMediaError` naming the media type, actual byte size, and the cap. Unlike the generic cap helper, the message is prefixed with the media type for clearer user feedback.","triggerScenarios":"Calling `validate_media` (from `send_media`) with a `max_bytes` limit where `path.stat().st_size > max_bytes`. When `max_bytes` is None this check is skipped entirely.","commonSituations":"Provider-specific limits (e.g. WhatsApp voice-note caps) exceeded by generated audio; inbound/outbound images over a configured limit; large screenshots.","solutions":["Shrink the media (re-encode, lower bitrate/resolution) below `max_bytes`.","Raise the `max_bytes` argument or `DEEPAGENTS_TALON_MAX_MEDIA_BYTES` if the provider supports larger uploads.","Catch `ChannelMediaError` and reply to the sender that the attachment exceeds the limit."],"exampleFix":"# before\nvalidate_media(media, max_bytes=16 * 1024 * 1024)  # voice note cap\n\n# after\nvalidate_media(transcode_to_opus(media, max_bytes=16 * 1024 * 1024), max_bytes=16 * 1024 * 1024)","handlingStrategy":"validation","validationCode":"path = Path(media.path)\nif max_bytes is not None and path.stat().st_size > max_bytes:\n    raise ValueError(f'{media.media_type} exceeds {max_bytes} bytes')","typeGuard":null,"tryCatchPattern":"try:\n    await channel.send_media(media)\nexcept ChannelMediaError as exc:\n    if 'too large' in str(exc):\n        await channel.send_text(f'{media.media_type} attachment is too large to send.')\n    else:\n        raise","preventionTips":["Transcode media per provider limits (voice notes, images) before send.","Pass explicit `max_bytes` per media type matching the provider's documented cap.","Log sizes at send time to catch creeping file sizes in CI-generated artifacts."],"tags":["media","size-limit","validation"],"backgroundTag":"file-too-large","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}