{"record":{"id":"31ff432b86d4c0e2","repo":"crewAIInc/crewAI","slug":"search-query-is-required","errorCode":null,"errorMessage":"search_query is required","messagePattern":"search_query is required","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/serper_dev_tool/serper_dev_tool.py","lineNumber":324,"sourceCode":"            if \"relatedSearches\" in results:\n                formatted_results[\"relatedSearches\"] = self._process_related_searches(\n                    results[\"relatedSearches\"]\n                )\n\n        elif search_type == \"news\":\n            if \"news\" in results:\n                formatted_results[\"news\"] = self._process_news_results(results[\"news\"])\n\n        return formatted_results\n\n    def _run(self, **kwargs: Any) -> FormattedResults:\n        \"\"\"Execute the search operation.\"\"\"\n        search_query: str | None = kwargs.get(\"search_query\") or kwargs.get(\"query\")\n        search_type: str = kwargs.get(\"search_type\", self.search_type)\n        save_file = kwargs.get(\"save_file\", self.save_file)\n\n        if not search_query:\n            raise ValueError(\"search_query is required\")\n\n        results = self._make_api_request(search_query, search_type)\n\n        formatted_results = {\n            \"searchParameters\": {\n                \"q\": search_query,\n                \"type\": search_type,\n                **results.get(\"searchParameters\", {}),\n            }\n        }\n\n        formatted_results.update(self._process_search_results(results, search_type))\n        formatted_results[\"credits\"] = results.get(\"credits\", 1)\n\n        if save_file:\n            _save_results_to_file(json.dumps(formatted_results, indent=2))\n\n        return formatted_results  # type: ignore[return-value]","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/serper_dev_tool/serper_dev_tool.py#L306-L342","documentation":"SerperDevTool._run raises ValueError(\"search_query is required\") when neither the search_query nor the query keyword argument is truthy. The tool checks kwargs.get(\"search_query\") or kwargs.get(\"query\") and, combined with there being no instance-level default query, an empty/missing query aborts before any request.","triggerScenarios":"Calling tool._run() with no arguments; calling _run(search_query=\"\") or _run(query=None); or an LLM agent producing a tool call that omits the query string.","commonSituations":"Agent frameworks generating malformed tool arguments (empty string query from the model), or test code invoking the tool without inputs. Very common when the tool schema is bypassed and _run is called directly.","solutions":["Pass a non-empty search string: tool._run(search_query=\"crewai\") (query= is also accepted).","If an agent is producing empty queries, add a description/example to the tool input schema or validate the model output before invoking the tool.","Wrap the call in try/except ValueError to degrade gracefully (return a prompt asking for a query)."],"exampleFix":"# before\nresult = serper_tool._run()\n\n# after\nresult = serper_tool._run(search_query=\"latest crewai release\")","handlingStrategy":"validation","validationCode":"query = (kwargs.get(\"search_query\") or kwargs.get(\"query\") or \"\").strip()\nif not query:\n    raise ValueError(\"A non-empty search_query must be provided\")\nresult = serper_tool._run(search_query=query)","typeGuard":"def has_search_query(kwargs: dict) -> bool:\n    return bool((kwargs.get(\"search_query\") or kwargs.get(\"query\") or \"\").strip())","tryCatchPattern":"try:\n    result = serper_tool._run(**kwargs)\nexcept ValueError as e:\n    if \"search_query is required\" in str(e):\n        return \"Please provide a search query.\"  # agent re-ask\n    raise","preventionTips":["Validate that the query is a non-empty string before invoking the tool.","When agents call the tool, make search_query a required schema field and reject empty model outputs."],"tags":["serper","input-validation","required-argument"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}