unclecode/crawl4ai · error · TypeError

{cls.__name__} must implement 'run(self, url: str, **kwargs)

Error message

{cls.__name__} must implement 'run(self, url: str, **kwargs)'

What it means

Error "{cls.__name__} must implement 'run(self, url: str, **kwargs)'" thrown in unclecode/crawl4ai.

Source

Thrown at crawl4ai/hub.py:31

    def __init__(self):
        self.logger = logging.getLogger(self.__class__.__name__)
        
    @abstractmethod
    async def run(self, url: str = "", **kwargs) -> str:
        """
        Implement this method to return JSON string.
        Must accept URL + arbitrary kwargs for flexibility.
        """
        pass

    def __init_subclass__(cls, **kwargs):
        """Enforce interface validation on subclassing"""
        super().__init_subclass__(**kwargs)
        
        # Verify run method signature
        run_method = cls.run
        if not run_method.__code__.co_argcount >= 2:  # self + url
            raise TypeError(f"{cls.__name__} must implement 'run(self, url: str, **kwargs)'")
            
        # Verify async nature
        if not inspect.iscoroutinefunction(run_method):
            raise TypeError(f"{cls.__name__}.run must be async")

class CrawlerHub:
    _crawlers: Dict[str, Type[BaseCrawler]] = {}

    @classmethod
    def _discover_crawlers(cls):
        """Dynamically load crawlers from /crawlers in 3 lines"""
        base_path = Path(__file__).parent / "crawlers"
        for crawler_dir in base_path.iterdir():
            if crawler_dir.is_dir():
                try:
                    module = importlib.import_module(
                        f"crawl4ai.crawlers.{crawler_dir.name}.crawler"
                    )

View on GitHub (pinned to 7e80152142)

Solutions

  1. Implement a run(self, url: str, **kwargs) method on the strategy class.
  2. Subclass BaseStrategy from crawl4ai.hub and implement the required run method.

Example fix

class MyStrategy(BaseStrategy):
    async def run(self, url: str, **kwargs): ...

When it happens

Trigger: Thrown at crawl4ai/hub.py:31 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of unclecode/crawl4ai@7e80152142 (2026-08-14). Data as JSON: /api/errors/8fc3a35c26d884f0. Report an issue: GitHub.