{"record":{"id":"53e7d823faa9fb30","repo":"langchain-ai/langchain","slug":"must-provide-one-of-url-base64-or-file-id","errorCode":null,"errorMessage":"Must provide one of: url, base64, or file_id","messagePattern":"Must provide one of: url, base64, or file_id","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/messages/content.py","lineNumber":1035,"sourceCode":"        index: Index of block in aggregate response.\n\n            Used during streaming.\n\n    Returns:\n        A properly formatted `ImageContentBlock`.\n\n    Raises:\n        ValueError: If no image 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    block = ImageContentBlock(type=\"image\", 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":1017,"sourceCodeEnd":1053,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/messages/content.py#L1017-L1053","documentation":"Raised by the `ImageContentBlock` constructor helper when none of `url`, `base64`, or `file_id` is provided. An image block must reference its payload somewhere; the helper validates this at construction time so the failure happens immediately rather than deep inside a provider call.","triggerScenarios":"Calling the image block constructor with only `mime_type`/`index`/`id`, or with all source arguments as None/empty; conditionally setting a source variable that ends up falsy/unset.","commonSituations":"Building blocks from optional config fields where the image source was never populated; passing an empty string `url=\"\"` after a template substitution failed; logic bugs where the source key name doesn't match the parameter name.","solutions":["Pass at least one of `url=`, `base64=`, or `file_id=` when constructing the block","Check the variable holding the source is non-empty before constructing: `if src: ImageContentBlock(url=src)`","Default to `base64` with `mime_type` when you have raw bytes"],"exampleFix":"# before\nblock = ImageContentBlock(type=\"image\")  # or helper call with no source args\n\n# after\nblock = ImageContentBlock(url=\"https://example.com/cat.png\")","handlingStrategy":"validation","validationCode":"def has_image_source_args(url, base64, file_id) -> bool:\n    return any([url, base64, file_id])","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Construct image blocks only where a source value is known non-empty","Fail upload/download steps loudly so sources are never silently missing","Prefer the typed constructors over raw dicts"],"tags":["image","content-blocks","validation","constructor"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}