{"record":{"id":"608eef19069f3210","repo":"crewAIInc/crewAI","slug":"query-is-required-either-in-constructor-or-method","errorCode":null,"errorMessage":"query is required either in constructor or method call","messagePattern":"query is required either in constructor or method call","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/brightdata_tool/brightdata_serp.py","lineNumber":177,"sourceCode":"            parse_results (bool): If True, returns structured data; else raw page (default: True).\n            results_count (str or int): Number of search results to fetch (default: \"10\").\n\n        Returns:\n            dict or str: Parsed JSON data from Bright Data if available, otherwise error message.\n        \"\"\"\n        query = query or self.query\n        search_engine = search_engine or self.search_engine\n        country = country or self.country\n        language = language or self.language\n        search_type = search_type or self.search_type\n        device_type = device_type or self.device_type\n        parse_results = (\n            parse_results if parse_results is not None else self.parse_results\n        )\n        results_count = kwargs.get(\"results_count\", \"10\")\n\n        if not query:\n            raise ValueError(\"query is required either in constructor or method call\")\n\n        query = urllib.parse.quote(query)\n        url = self.get_search_url(search_engine, query)\n\n        params = []\n\n        if country:\n            params.append(f\"gl={country}\")\n\n        if language:\n            params.append(f\"hl={language}\")\n\n        if results_count:\n            params.append(f\"num={results_count}\")\n\n        if parse_results:\n            params.append(\"brd_json=1\")\n","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/brightdata_tool/brightdata_serp.py#L159-L195","documentation":"Raised by BrightDataSERPTool._run when the query resolves to falsy at both the call-site and constructor level (query = query or self.query). The SERP tool then URL-encodes the query into a search URL (google/bing/yandex per get_search_url), so an empty query cannot proceed.","triggerScenarios":"Constructing the tool without query and calling tool.run() bare; tool.run(query='') from an agent whose input template produced an empty string; passing only filters like country/search_type.","commonSituations":"Prompt variables interpolating to empty, agents omitting the query argument, constructor configured with everything except query.","solutions":["Pass query at call time: tool.run(query='best crm software', country='us').","Or set it in the constructor: BrightDataSERPTool(query='best crm software').","Validate agent-produced inputs are non-empty before invoking the tool."],"exampleFix":"# before\nresult = tool.run(country='us')  # ValueError: query is required\n\n# after\nresult = tool.run(query='best crm software', country='us')","handlingStrategy":"validation","validationCode":"def validate_serp_query(query: str | None) -> str:\n    if not query or not query.strip():\n        raise ValueError(\"query is required either in constructor or method call\")\n    return query.strip()\n\nresult = tool.run(query=validate_serp_query(query))","typeGuard":"def has_serp_query(call_kwargs: dict, tool) -> bool:\n    return bool((call_kwargs.get(\"query\") or tool.query))","tryCatchPattern":"try:\n    result = tool.run(country='us')\nexcept ValueError as e:\n    if \"query is required\" in str(e):\n        result = tool.run(query=default_query(), country='us')\n    else:\n        raise","preventionTips":["Bind query in the constructor for fixed-monitoring use cases.","Trim and non-empty-check agent-supplied queries before dispatch.","Document that the SERP tool accepts no filter-only invocations."],"tags":["bright-data","serp","validation","required-parameter"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}