{"record":{"id":"3b249ff4516c00af","repo":"crewAIInc/crewAI","slug":"invalid-url-format","errorCode":null,"errorMessage":"Invalid URL format","messagePattern":"Invalid URL format","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/selenium_scraping_tool/selenium_scraping_tool.py","lineNumber":41,"sourceCode":"        description=\"Mandatory css reference for element to scrape from the website\",\n    )\n\n    @field_validator(\"website_url\")\n    @classmethod\n    def validate_website_url(cls, v: str) -> str:\n        if not v:\n            raise ValueError(\"Website URL cannot be empty\")\n\n        if len(v) > 2048:  # Common maximum URL length\n            raise ValueError(\"URL is too long (max 2048 characters)\")\n\n        if not re.match(r\"^https?://\", v):\n            raise ValueError(\"URL must start with http:// or https://\")\n\n        try:\n            result = urlparse(v)\n            if not all([result.scheme, result.netloc]):\n                raise ValueError(\"Invalid URL format\")\n        except Exception as e:\n            raise ValueError(f\"Invalid URL: {e!s}\") from e\n\n        if re.search(r\"\\s\", v):\n            raise ValueError(\"URL cannot contain whitespace\")\n\n        return v\n\n\nclass SeleniumScrapingTool(BaseTool):\n    name: str = \"Read a website content\"\n    description: str = \"A tool that can be used to read a website content.\"\n    args_schema: type[BaseModel] = SeleniumScrapingToolSchema\n    website_url: str | None = None\n    driver: Any | None = None\n    cookie: dict[str, Any] | None = None\n    wait_time: int | None = 3\n    css_element: str | None = None","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/selenium_scraping_tool/selenium_scraping_tool.py#L23-L59","documentation":"Pydantic field_validator error from SeleniumScrapingToolSchema raised when urlparse(v) succeeds but the parsed URL lacks a scheme or netloc component (all([result.scheme, result.netloc]) is False). This catches URLs that pass the earlier http/https prefix check but are structurally incomplete — most notably 'https://' with no host, or malformed inputs the regex prefix happened to accept.","triggerScenarios":"Passing 'https:///path' (empty host), 'https://?q=1', or values where urlparse yields an empty netloc despite an https:// prefix; note the inner raise is inside a try whose except wraps it as 'Invalid URL: {e}' only if an exception propagates — the direct raise produces this exact message.","commonSituations":"String-building URLs with a bug that drops the host (f'https://{host}{path}' with empty host); truncated URLs from copy-paste; URLs assembled from config where the domain variable is empty.","solutions":["Ensure the URL has a real hostname: 'https://example.com/page', not 'https:///page'.","If constructing URLs from parts, validate each component (host non-empty) before joining.","Test the URL with urllib.parse.urlparse yourself and require both scheme and netloc."],"exampleFix":"# before\nurl = f\"https://{host}/page\"  # host == \"\" -> \"https:///page\"\ntool = SeleniumScrapingTool(website_url=url, css_element=\"article\")\n\n# after\nif not host:\n    raise ValueError(\"host must not be empty\")\nurl = f\"https://{host}/page\"\ntool = SeleniumScrapingTool(website_url=url, css_element=\"article\")","handlingStrategy":"validation","validationCode":"from urllib.parse import urlparse\n\np = urlparse(url)\nif not (p.scheme in (\"http\", \"https\") and p.netloc):\n    raise ValueError(f\"URL missing host: {url!r}\")","typeGuard":null,"tryCatchPattern":"from pydantic import ValidationError\n\ntry:\n    tool = SeleniumScrapingTool(website_url=url, css_element=css)\nexcept ValidationError as e:\n    if \"Invalid URL format\" in str(e):\n        raise ValueError(f\"assemble URLs with a non-empty host: got {url!r}\") from e\n    raise","preventionTips":["When building URLs from parts (f'https://{host}{path}'), assert host is non-empty first.","Run urlparse-based checks (scheme + netloc) on config-derived URLs at startup."],"tags":["validation","url","selenium","malformed-url"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}