crewAIInc/crewAI · error · ValueError
query is required either in constructor or method call
Error message
query is required either in constructor or method call
What it means
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.
Source
Thrown at lib/crewai-tools/src/crewai_tools/tools/brightdata_tool/brightdata_serp.py:177
parse_results (bool): If True, returns structured data; else raw page (default: True).
results_count (str or int): Number of search results to fetch (default: "10").
Returns:
dict or str: Parsed JSON data from Bright Data if available, otherwise error message.
"""
query = query or self.query
search_engine = search_engine or self.search_engine
country = country or self.country
language = language or self.language
search_type = search_type or self.search_type
device_type = device_type or self.device_type
parse_results = (
parse_results if parse_results is not None else self.parse_results
)
results_count = kwargs.get("results_count", "10")
if not query:
raise ValueError("query is required either in constructor or method call")
query = urllib.parse.quote(query)
url = self.get_search_url(search_engine, query)
params = []
if country:
params.append(f"gl={country}")
if language:
params.append(f"hl={language}")
if results_count:
params.append(f"num={results_count}")
if parse_results:
params.append("brd_json=1")
View on GitHub (pinned to 754d7323be)
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.
Example fix
# before result = tool.run(country='us') # ValueError: query is required # after result = tool.run(query='best crm software', country='us')
Defensive patterns
Strategy: validation
Validate before calling
def validate_serp_query(query: str | None) -> str:
if not query or not query.strip():
raise ValueError("query is required either in constructor or method call")
return query.strip()
result = tool.run(query=validate_serp_query(query)) Type guard
def has_serp_query(call_kwargs: dict, tool) -> bool:
return bool((call_kwargs.get("query") or tool.query)) Try / catch
try:
result = tool.run(country='us')
except ValueError as e:
if "query is required" in str(e):
result = tool.run(query=default_query(), country='us')
else:
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Prompt variables interpolating to empty, agents omitting the query argument, constructor configured with everything except query.
Related errors
- dataset_type is required either in constructor or method cal
- url is required either in constructor or method call
- url is required either in constructor or method call
- Query is required
- Unable to find the dataset for {dataset_type}. Please make s
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/608eef19069f3210.
Report an issue: GitHub.