{"record":{"id":"2aebed5cc2d1a667","repo":"langchain-ai/langchain","slug":"mime-type-is-required-when-using-base64-data","errorCode":null,"errorMessage":"mime_type is required when using base64 data","messagePattern":"mime_type is required when using base64 data","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/messages/content.py","lineNumber":1101,"sourceCode":"    Returns:\n        A properly formatted `VideoContentBlock`.\n\n    Raises:\n        ValueError: If no video source is provided or if `base64` is used without\n            `mime_type`.\n\n    !!! note\n\n        The `id` is generated automatically if not provided, using a UUID4 format\n        prefixed with `'lc_'` to indicate it is a LangChain-generated ID.\n    \"\"\"\n    if not any([url, base64, file_id]):\n        msg = \"Must provide one of: url, base64, or file_id\"\n        raise ValueError(msg)\n\n    if base64 and not mime_type:\n        msg = \"mime_type is required when using base64 data\"\n        raise ValueError(msg)\n\n    block = VideoContentBlock(type=\"video\", id=ensure_id(id))\n\n    if url is not None:\n        block[\"url\"] = url\n    if base64 is not None:\n        block[\"base64\"] = base64\n    if file_id is not None:\n        block[\"file_id\"] = file_id\n    if mime_type is not None:\n        block[\"mime_type\"] = mime_type\n    if index is not None:\n        block[\"index\"] = index\n\n    extras = {k: v for k, v in kwargs.items() if v is not None}\n    if extras:\n        block[\"extras\"] = extras\n","sourceCodeStart":1083,"sourceCodeEnd":1119,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/messages/content.py#L1083-L1119","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nblock = VideoContentBlock(base64=b64_data)\n\n# after\nblock = VideoContentBlock(base64=b64_data, mime_type=\"video/mp4\")","handlingStrategy":"validation","validationCode":"def valid_video_b64_args(base64, mime_type) -> bool:\n    return not base64 or bool(mime_type)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["video","base64","mime-type","content-blocks","validation"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}