deepset-ai/haystack · error · TypeError
Unsupported data source type: {type(source).__name__}
Error message
Unsupported data source type: {type(source).__name__} What it means
FileTypeRouter.run accepts only str, Path, and ByteStream sources; any other type raises this TypeError identifying the offending type name.
Source
Thrown at haystack/components/routers/file_type_router.py:176
for source, meta_dict in zip(sources, meta_list, strict=True):
if isinstance(source, str):
source = Path(source)
if isinstance(source, Path):
if not source.exists():
if self._raise_on_failure:
raise FileNotFoundError(f"File not found: {source}")
logger.warning("File not found: {source}. Skipping it.", source=source)
mime_types["failed"].append(source)
continue
mime_type = _guess_mime_type(source)
elif isinstance(source, ByteStream):
mime_type = source.mime_type
else:
raise TypeError(f"Unsupported data source type: {type(source).__name__}")
# If we have metadata, we convert the source to ByteStream and add the metadata
if meta_dict:
try:
source = get_bytestream_from_source(source)
except Exception as e:
if self._raise_on_failure:
raise e
logger.warning("Could not read {source}. Skipping it. Error: {error}", source=source, error=e)
mime_types["failed"].append(source)
continue
source.meta.update(meta_dict)
matched = False
if mime_type:
# Try exact equality first so MIMEs containing regex metacharacters (e.g. the `+` in
# `image/svg+xml`) match themselves before the regex fallback gets a chance to misread them.View on GitHub (pinned to e318778c9b)
Solutions
- Convert the source to a Path/str for file paths, or wrap bytes in ByteStream(data=..., mime_type=...)
- Check the type reported in the message and adapt upstream code to yield supported types
Example fix
# before router.run(sources=[b"raw pdf bytes"]) # after from haystack.dataclasses import ByteStream router.run(sources=[ByteStream(data=b"raw pdf bytes", mime_type="application/pdf")])
Defensive patterns
Strategy: type-guard
Validate before calling
from haystack.dataclasses import ByteStream from pathlib import Path bad = [s for s in sources if not isinstance(s, (str, Path, ByteStream))]
Type guard
def is_valid_source(source) -> bool:
from haystack.dataclasses import ByteStream
from pathlib import Path
return isinstance(source, (str, Path, ByteStream)) Try / catch
try:
result = router.run(sources=sources)
except TypeError as e:
if "Unsupported data source type" in str(e):
sources = [s if is_valid_source(s) else ByteStream(data=bytes(s)) for s in sources]
result = router.run(sources=sources)
else:
raise Prevention
- Normalize all sources to str, Path, or ByteStream before run
- Wrap raw bytes in ByteStream with an explicit mime_type
- Narrow the type of upstream component outputs feeding sources
When it happens
Trigger: run(sources=[b'bytes']) or run(sources=[{'path': 'f.pdf'}]) — passing raw bytes, dicts, or other objects instead of str/Path/ByteStream.
Common situations: Confusing raw file contents with file paths; passing Document objects from other Haystack components instead of ByteStream; integrating with code that yields different source types.
Related errors
- LLM evaluator expects all input values to be lists but recei
- Expected ChatMessage object, got {type(last_message)}
- Invalid template for condition: {condition_value}
- Invalid template for output: {output!r} (type: {type(output)
- Invalid template for output: {output}
AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30).
Data as JSON: /api/errors/ff965a44eb41f837.
Report an issue: GitHub.