{"record":{"id":"8ed298a0a866e66b","repo":"crewAIInc/crewAI","slug":"invalid-mode-mode-must-be-either-scrape-or","errorCode":null,"errorMessage":"Invalid mode: {mode}. Must be either 'scrape' or 'crawl'","messagePattern":"Invalid mode: (.+?)\\. Must be either 'scrape' or 'crawl'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/spider_tool/spider_tool.py","lineNumber":175,"sourceCode":"            ValueError: If URL is invalid or missing, or if mode is invalid.\n            ImportError: If spider-client package is not properly installed.\n            ConnectionError: If network connection fails while accessing the URL.\n            Exception: For other runtime errors.\n        \"\"\"\n        try:\n            params = {}\n            url = website_url or self.website_url\n\n            if not url:\n                raise ValueError(\n                    \"Website URL must be provided either during initialization or execution\"\n                )\n\n            if not self._validate_url(url):\n                raise ValueError(f\"Invalid URL format: {url}\")\n\n            if mode not in [\"scrape\", \"crawl\"]:\n                raise ValueError(\n                    f\"Invalid mode: {mode}. Must be either 'scrape' or 'crawl'\"\n                )\n\n            params = {\n                \"request\": self.config.DEFAULT_REQUEST_MODE,\n                \"filter_output_svg\": self.config.FILTER_SVG,\n                \"return_format\": self.config.DEFAULT_RETURN_FORMAT,\n            }\n\n            if mode == \"crawl\":\n                params[\"limit\"] = self.config.DEFAULT_CRAWL_LIMIT\n\n            if self.custom_params:\n                params.update(self.custom_params)\n\n            action = (\n                self.spider.scrape_url if mode == \"scrape\" else self.spider.crawl_url\n            )","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/spider_tool/spider_tool.py#L157-L193","documentation":"SpiderTool supports exactly two modes: 'scrape' (single page) and 'crawl' (site-wide up to DEFAULT_CRAWL_LIMIT). _run raises ValueError when the mode argument is anything else; the check is case-sensitive, so 'Scrape' or 'CRAWL' also fail.","triggerScenarios":"Calling _run(mode=\"scraping\"), mode=\"spider\", or mode=\"SCRAPE\" (capitalized); an LLM agent inventing mode values not in the tool schema; configuration files with a typo'd mode string.","commonSituations":"Agents producing free-form mode arguments; users assuming modes like 'screenshot' or 'search' exist because the Spider API supports them; casing inconsistencies between config and the tool's expectation.","solutions":["Use exactly \"scrape\" or \"crawl\" (lowercase) for the mode argument.","Normalize incoming mode strings: mode.strip().lower() before calling _run.","Constrain agent-facing schemas to an enum of the two valid values so the model cannot emit others."],"exampleFix":"# before\nresult = tool._run(website_url=url, mode=\"SCRAPE\")\n\n# after\nresult = tool._run(website_url=url, mode=\"scrape\")","handlingStrategy":"validation","validationCode":"mode = (mode or \"scrape\").strip().lower()\nif mode not in {\"scrape\", \"crawl\"}:\n    raise ValueError(f\"mode must be 'scrape' or 'crawl', got {mode!r}\")","typeGuard":"def is_spider_mode(value: str) -> bool:\n    return isinstance(value, str) and value.strip().lower() in {\"scrape\", \"crawl\"}","tryCatchPattern":"try:\n    result = tool._run(website_url=url, mode=mode)\nexcept ValueError as e:\n    if \"Invalid mode\" in str(e):\n        result = tool._run(website_url=url, mode=\"scrape\")  # safe default\n    else:\n        raise","preventionTips":["Lowercase and trim mode strings at your boundary.","Expose mode as an enum (scrape|crawl) in agent-facing tool schemas."],"tags":["spider","validation","enum","input-validation"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}