{"record":{"id":"de5c4dad8d9a888c","repo":"lancedb/lancedb","slug":"each-input-should-be-either-str-bytes-path-or-im","errorCode":null,"errorMessage":"Each input should be either str, bytes, Path or Image.","messagePattern":"Each input should be either str, bytes, Path or Image\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/python/lancedb/embeddings/voyageai.py","lineNumber":113,"sourceCode":"            # Read video file and encode as base64\n            with open(input_data, \"rb\") as f:\n                video_bytes = f.read()\n            video_str = base64.b64encode(video_bytes).decode(\"utf-8\")\n            content = {\n                \"type\": \"video_base64\",\n                \"video_base64\": video_str,\n            }\n        else:\n            img = PIL_Image.open(input_data)\n            buffered = BytesIO()\n            img.save(buffered, format=\"JPEG\")\n            img_str = base64.b64encode(buffered.getvalue()).decode(\"utf-8\")\n            content = {\n                \"type\": \"image_base64\",\n                \"image_base64\": \"data:image/jpeg;base64,\" + img_str,\n            }\n    else:\n        raise ValueError(\"Each input should be either str, bytes, Path or Image.\")\n\n    return {\"content\": [content]}\n\n\ndef sanitize_multimodal_input(inputs: Union[TEXT, IMAGES]) -> List[Any]:\n    \"\"\"\n    Sanitize the input to the embedding function.\n    \"\"\"\n    PIL_Image = attempt_import_or_raise(\"PIL.Image\", \"pillow\")\n    if isinstance(inputs, (str, bytes, Path, PIL_Image.Image)):\n        inputs = [inputs]\n    elif isinstance(inputs, list):\n        pass  # Already a list, use as-is\n    elif isinstance(inputs, pa.Array):\n        inputs = inputs.to_pylist()\n    elif isinstance(inputs, pa.ChunkedArray):\n        inputs = inputs.combine_chunks().to_pylist()\n    else:","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/lancedb/lancedb/blob/c7b051aff7039333a3f61b79217246c27676806a/python/python/lancedb/embeddings/voyageai.py#L95-L131","documentation":"Voyage AI multimodal inputs must each be str, bytes, Path, or PIL Image; transform_input converts each item into the content dict Voyage expects. An item of any other type hits the else branch and raises ValueError listing the accepted types.","triggerScenarios":"Calling compute_source_embeddings / embed with an input list containing an unsupported element (numpy array, dict, list-of-lists, None) that sanitize_multimodal_input passes through to transform_input.","commonSituations":"Mixing numpy image arrays with text in a batch; passing None placeholders; nested lists from misshaped Arrow columns; passing torch tensors.","solutions":["Convert image arrays with PIL.Image.fromarray(arr) before embedding","Open bytes with PIL.Image.open(io.BytesIO(data))","Filter or fix None/invalid entries in the input list","Ensure Arrow columns are flattened to lists of str/bytes/Path/Image"],"exampleFix":"// before\nembed([\"text\", np_img])  # ValueError\n// after\nembed([\"text\", Image.fromarray(np_img)])","handlingStrategy":"type-guard","validationCode":"from pathlib import Path\n\ndef is_valid_voyage_item(x) -> bool:\n    try:\n        from PIL import Image\n        return isinstance(x, (str, bytes, Path, Image.Image))\n    except ImportError:\n        return isinstance(x, (str, bytes, Path))\n\ndef validate_inputs(items):\n    for x in items:\n        if not is_valid_voyage_item(x):\n            raise TypeError(f\"Unsupported item type: {type(x)}\")","typeGuard":"def coerce_voyage_item(x):\n    from PIL import Image\n    if isinstance(x, (str, bytes, Path, Image.Image)):\n        return x\n    if hasattr(x, \"__array_interface__\"):\n        import numpy as np\n        return Image.fromarray(np.asarray(x))\n    raise TypeError(f\"Unsupported item type: {type(x)}\")","tryCatchPattern":"try:\n    vectors = emb.compute_source_embeddings(inputs)\nexcept ValueError as e:\n    if \"str, bytes, Path or Image\" in str(e):\n        inputs = [coerce_voyage_item(x) for x in inputs]\n        vectors = emb.compute_source_embeddings(inputs)\n    else:\n        raise","preventionTips":["Coerce every batch element to str/bytes/Path/PIL before calling","Drop or fix None entries and nested lists before embedding","Validate batch shape/types in a preprocessing step"],"tags":["python","type-error","multimodal","voyageai"],"backgroundTag":"invalid-argument-value","analyzedSha":"c7b051aff7039333a3f61b79217246c27676806a","analyzedAt":"2026-09-08T23:42:37.579Z","contentChangedAt":"2026-09-08T23:42:37.579Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}