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

  1. Always pass `mime_type` alongside `base64`, e.g. `mime_type="video/mp4"`
  2. Derive it from the source file: `mimetypes.guess_type(path)[0]`
  3. 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

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


AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14). Data as JSON: /api/errors/2aebed5cc2d1a667. Report an issue: GitHub.