crewAIInc/crewAI · error · ValueError

Error loading loader for {self}: {e}

Error message

Error loading loader for {self}: {e}

What it means

get_loader() dynamically imports crewai_tools.rag.loaders.<module> and instantiates the loader class; any exception in that process (ModuleNotFoundError for an optional loader dependency such as unstructured, youtube extras, pymysql/psycopg2 for DB loaders, or constructor failure) is wrapped as ValueError('Error loading loader for <DataType>: <cause>').

Source

Thrown at lib/crewai-tools/src/crewai_tools/rag/data_types.py:95

            DataType.YOUTUBE_CHANNEL: (
                "youtube_channel_loader",
                "YoutubeChannelLoader",
            ),
            DataType.GITHUB: ("github_loader", "GithubLoader"),
            DataType.DOCS_SITE: ("docs_site_loader", "DocsSiteLoader"),
            DataType.MYSQL: ("mysql_loader", "MySQLLoader"),
            DataType.POSTGRES: ("postgres_loader", "PostgresLoader"),
        }

        if self not in loaders:
            raise ValueError(f"No loader defined for {self}")
        module_name, class_name = loaders[self]
        module_path = f"crewai_tools.rag.loaders.{module_name}"
        try:
            module = import_module(module_path)
            return cast(BaseLoader, getattr(module, class_name)())
        except Exception as e:
            raise ValueError(f"Error loading loader for {self}: {e}") from e


class DataTypes:
    @staticmethod
    def from_content(content: str | Path | None = None) -> DataType:
        if content is None:
            return DataType.TEXT

        if isinstance(content, Path):
            content = str(content)

        is_url = False
        if isinstance(content, str):
            try:
                url = urlparse(content)
                is_url = bool(url.scheme in ("http", "https") and url.netloc)
            except Exception:  # noqa: S110
                pass

View on GitHub (pinned to 754d7323be)

Solutions

  1. Read e.__cause__ — it names the missing module or constructor error
  2. Install the specific dependency (e.g. uv add pymysql for MySQLLoader, psycopg2-binary for PostgresLoader)
  3. Reinstall crewai-tools with its rag/reader extras to pull optional deps
  4. Pin versions once working to avoid dependency drift

Example fix

# before
try:
    loader = dtype.get_loader()
except ValueError:
    raise
# after
try:
    loader = dtype.get_loader()
except ValueError as e:
    cause = str(e.__cause__)
    logger.error('loader load failed: %s', cause)
    # e.g. "No module named 'pymysql'" -> uv add pymysql
    raise
Defensive patterns

Strategy: try-catch

Validate before calling

deps = {DataType.MYSQL: 'pymysql', DataType.POSTGRES: 'psycopg2'}
import importlib
for dt, mod in deps.items():
    if dtype == dt:
        importlib.import_module(mod)  # raises early with the missing module name

Try / catch

try:
    loader = dtype.get_loader()
except ValueError as e:
    cause = str(e.__cause__ or '')
    if 'No module named' in cause:
        raise SystemExit(f'missing loader dependency: {cause}') from e
    raise

Prevention

When it happens

Trigger: Selecting a DB loader (MySQLLoader/PostgresLoader) without pymysql/psycopg2 installed; DOCX/PDF loaders requiring unstructured/extra packages; partial installs missing loader submodules.

Common situations: Using crewai-tools rag with a niche content type on a slim install; CI images trimmed of optional deps; upgrading crewai-tools changes a loader's dependency set.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/c255736150a87e8c. Report an issue: GitHub.