{"record":{"id":"95ac887db56e3466","repo":"crewAIInc/crewAI","slug":"query-is-required","errorCode":null,"errorMessage":"Query is required","messagePattern":"Query is required","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/brave_search_tool/brave_search_tool.py","lineNumber":75,"sourceCode":"                \"BRAVE_API_KEY environment variable is required for BraveSearchTool\"\n            )\n\n    def _run(\n        self,\n        **kwargs: Any,\n    ) -> Any:\n        current_time = time.time()\n        if (current_time - self._last_request_time) < self._min_request_interval:\n            time.sleep(\n                self._min_request_interval - (current_time - self._last_request_time)\n            )\n        BraveSearchTool._last_request_time = time.time()\n\n        try:\n            # Fallback to \"query\" or \"search_query\" for backwards compatibility\n            query = kwargs.get(\"q\") or kwargs.get(\"query\") or kwargs.get(\"search_query\")\n            if not query:\n                raise ValueError(\"Query is required\")\n\n            payload = {\"q\": query}\n\n            if country := kwargs.get(\"country\"):\n                payload[\"country\"] = country\n\n            # Fallback to \"search_language\" for backwards compatibility\n            if search_lang := kwargs.get(\"search_lang\") or kwargs.get(\n                \"search_language\"\n            ):\n                payload[\"search_lang\"] = search_lang\n\n            # Fallback to deprecated n_results parameter if no count is provided\n            count = kwargs.get(\"count\")\n            if count is not None:\n                payload[\"count\"] = count\n            else:\n                payload[\"count\"] = self.n_results","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/brave_search_tool/brave_search_tool.py#L57-L93","documentation":"Raised by BraveSearchTool._run when no search query can be resolved. The method falls back across three keyword names — q, then query, then search_query — and if all are missing/empty it raises this ValueError before any HTTP call is made.","triggerScenarios":"Calling tool.run() with no arguments; calling tool.run(query='') or with only optional params like count/country; an agent invoking the tool with a differently-named parameter (e.g. search_term) that none of the three fallbacks match.","commonSituations":"LLM agents renaming the query parameter between calls, empty-string queries produced by templated prompts, migration from another search tool whose parameter is named search_query but the value evaluates falsy.","solutions":["Pass the query under one of the accepted names: q, query, or search_query.","Prefer positional invocation: tool.run('best crewai tutorials') which maps to q.","If an agent generates the call, tighten the tool's description/backstory so it always supplies the query parameter.","Guard the input: reject empty or whitespace-only strings before invoking the tool."],"exampleFix":"# before\nresult = tool.run(count=5)  # ValueError: Query is required\n\n# after\nresult = tool.run(q='crewai tutorials', count=5)","handlingStrategy":"validation","validationCode":"def clean_query(q=None, query=None, search_query=None):\n    value = q or query or search_query\n    if not value or not value.strip():\n        raise ValueError(\"Query is required\")\n    return value.strip()\n\nquery = clean_query(**tool_kwargs)\nresult = tool.run(q=query)","typeGuard":"def has_valid_query(kwargs: dict) -> bool:\n    v = kwargs.get(\"q\") or kwargs.get(\"query\") or kwargs.get(\"search_query\")\n    return isinstance(v, str) and bool(v.strip())","tryCatchPattern":"try:\n    result = tool.run(q=query)\nexcept ValueError as e:\n    if str(e) == \"Query is required\":\n        # regenerate/repair the query, then retry once\n        query = fallback_query_from_context()\n        result = tool.run(q=query)\n    else:\n        raise","preventionTips":["Normalize all callers to the canonical q parameter name.","Reject empty/whitespace queries before tool dispatch.","In agent task descriptions, state explicitly that the search_query/q argument is mandatory."],"tags":["brave-search","validation","required-parameter"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}