langchain-ai/langchain · error · ValueError
mime_type is required when using base64 data
Error message
mime_type is required when using base64 data
What it means
Raised by the `VideoContentBlock` constructor helper when `base64` is given without `mime_type`. A raw base64 video payload is unusable downstream without knowing the container/codec format, so the helper requires the pair together.
Source
Thrown at libs/core/langchain_core/messages/content.py:1101
Returns:
A properly formatted `VideoContentBlock`.
Raises:
ValueError: If no video source is provided or if `base64` is used without
`mime_type`.
!!! note
The `id` is generated automatically if not provided, using a UUID4 format
prefixed with `'lc_'` to indicate it is a LangChain-generated ID.
"""
if not any([url, base64, file_id]):
msg = "Must provide one of: url, base64, or file_id"
raise ValueError(msg)
if base64 and not mime_type:
msg = "mime_type is required when using base64 data"
raise ValueError(msg)
block = VideoContentBlock(type="video", id=ensure_id(id))
if url is not None:
block["url"] = url
if base64 is not None:
block["base64"] = base64
if file_id is not None:
block["file_id"] = file_id
if mime_type is not None:
block["mime_type"] = mime_type
if index is not None:
block["index"] = index
extras = {k: v for k, v in kwargs.items() if v is not None}
if extras:
block["extras"] = extras
View on GitHub (pinned to e32fa9a52e)
Solutions
- Always pass `mime_type` alongside `base64`, e.g. `mime_type="video/mp4"`
- Derive it from the source file: `mimetypes.guess_type(path)[0]`
- If you only have a URL, pass `url=` instead — no mime_type required there
Example fix
# before block = VideoContentBlock(base64=b64_data) # after block = VideoContentBlock(base64=b64_data, mime_type="video/mp4")
Defensive patterns
Strategy: validation
Validate before calling
def valid_video_b64_args(base64, mime_type) -> bool:
return not base64 or bool(mime_type) Prevention
- Thread the source file's mime type through the encode step
- Use mimetypes.guess_type() when the type isn't given explicitly
- Prefer url= when you don't want to manage mime types
When it happens
Trigger: Calling the video block helper with `base64="..."` but no `mime_type="video/mp4"`; code that sets mime_type conditionally and skips it for the base64 branch.
Common situations: Encoding uploads to base64 but forgetting to forward the original content type; assuming mp4 is inferred by default; porting image code (where the check differs) to video.
Related errors
- mime_type key is required for base64 data.
- Unsupported source type. Only 'url' and 'base64' are support
- Keys base64, url, or file_id required for file blocks.
- Key base64 is required for audio blocks.
- Block of type {block['type']} is not supported.
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/2aebed5cc2d1a667.
Report an issue: GitHub.