unclecode/crawl4ai · error · ValueError

extraction_strategy must be an instance of ExtractionStrateg

Error message

extraction_strategy must be an instance of ExtractionStrategy

What it means

ValueError from CrawlerRunConfig.__init__: extraction_strategy was supplied but is not an instance of ExtractionStrategy (and not None). The config validates early so failures appear at setup rather than mid-crawl.

Source

Thrown at crawl4ai/async_configs.py:1841:1009

        # Connection Parameters
        self.stream = stream
        self.method = method

        # Robots.txt Handling Parameters
        self.check_robots_txt = check_robots_txt

        # User Agent Parameters
        self.user_agent = user_agent
        self.user_agent_mode = user_agent_mode
        self.user_agent_generator_config = user_agent_generator_config

        # Validate type of extraction strategy and chunking strategy if they are provided
        if self.extraction_strategy is not None and not isinstance(
            self.extraction_strategy, ExtractionStrategy
        ):
            raise ValueError(
                "extraction_strategy must be an instance of ExtractionStrategy"
            )
        if self.chunking_strategy is not None and not isinstance(
            self.chunking_strategy, ChunkingStrategy
        ):
            raise ValueError(
                "chunking_strategy must be an instance of ChunkingStrategy"
            )

        # Set default chunking strategy if None
        if self.chunking_strategy is None:
            self.chunking_strategy = RegexChunking()

        # Deep Crawl Parameters
        self.deep_crawl_strategy = deep_crawl_strategy
        
        # Experimental Parameters
        self.experimental = experimental or {}

View on GitHub (pinned to 7e80152142)

Solutions

  1. Instantiate: extraction_strategy=JsonCssExtractionStrategy(schema=...)
  2. For custom strategies, subclass crawl4ai.extraction_strategy.ExtractionStrategy and implement its abstract methods
  3. Pass None (default) when you do not want extraction

Example fix

# before
config = CrawlerRunConfig(extraction_strategy=JsonCssExtractionStrategy)

# after
from crawl4ai import JsonCssExtractionStrategy
config = CrawlerRunConfig(
    extraction_strategy=JsonCssExtractionStrategy(schema={"baseSelector": "a", "fields": []})
)
Defensive patterns

Strategy: type-guard

Validate before calling

from crawl4ai.extraction_strategy import ExtractionStrategy
assert extraction_strategy is None or isinstance(extraction_strategy, ExtractionStrategy), "extraction_strategy must be an ExtractionStrategy instance"

Type guard

from crawl4ai.extraction_strategy import ExtractionStrategy

def is_extraction_strategy(s) -> bool:
    return s is None or isinstance(s, ExtractionStrategy)

Try / catch

try:
    config = CrawlerRunConfig(extraction_strategy=strat)
except ValueError:
    raise TypeError("extraction strategies must be instantiated ExtractionStrategy subclasses")

Prevention

When it happens

Trigger: arun(url, config=CrawlerRunConfig(extraction_strategy='css')) or passing a class instead of an instance (extraction_strategy=JsonCssExtractionStrategy - missing parentheses), or a custom object not subclassing ExtractionStrategy.

Common situations: Forgetting to instantiate the strategy class; passing a dict of strategy params hoping the crawler builds it; migrating old code where a string name used to work via a different API; duck-typed custom strategy that never subclassed the base.

Related errors


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