{"record":{"id":"94d1096afc0680cb","repo":"huggingface/smolagents","slug":"you-must-install-package-ddgs-to-run-this-tool","errorCode":null,"errorMessage":"You must install package `ddgs` to run this tool: for instance run `pip install ddgs`.","messagePattern":"You must install package `ddgs` to run this tool: for instance run `pip install ddgs`\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"src/smolagents/default_tools.py","lineNumber":135,"sourceCode":"        >>> print(results)\n        ```\n    \"\"\"\n\n    name = \"web_search\"\n    description = \"\"\"Performs a duckduckgo web search based on your query (think a Google search) then returns the top search results.\"\"\"\n    inputs = {\"query\": {\"type\": \"string\", \"description\": \"The search query to perform.\"}}\n    output_type = \"string\"\n\n    def __init__(self, max_results: int = 10, rate_limit: float | None = 1.0, **kwargs):\n        super().__init__()\n        self.max_results = max_results\n        self.rate_limit = rate_limit\n        self._min_interval = 1.0 / rate_limit if rate_limit else 0.0\n        self._last_request_time = 0.0\n        try:\n            from ddgs import DDGS\n        except ImportError as e:\n            raise ImportError(\n                \"You must install package `ddgs` to run this tool: for instance run `pip install ddgs`.\"\n            ) from e\n        self.ddgs = DDGS(**kwargs)\n\n    def forward(self, query: str) -> str:\n        self._enforce_rate_limit()\n        results = self.ddgs.text(query, max_results=self.max_results)\n        if len(results) == 0:\n            raise Exception(\"No results found! Try a less restrictive/shorter query.\")\n        postprocessed_results = [f\"[{result['title']}]({result['href']})\\n{result['body']}\" for result in results]\n        return \"## Search Results\\n\\n\" + \"\\n\\n\".join(postprocessed_results)\n\n    def _enforce_rate_limit(self) -> None:\n        import time\n\n        # No rate limit enforced\n        if not self.rate_limit:\n            return","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/default_tools.py#L117-L153","documentation":"Raised in DuckDuckGoSearchTool.__init__ when the optional `ddgs` package is not installed. smolagents keeps search dependencies optional, so the tool fails fast at construction time with an ImportError chained from the underlying ModuleNotFoundError.","triggerScenarios":"Instantiating DuckDuckGoSearchTool (or referencing it via the default tools) in an environment where `import ddgs` raises ImportError — i.e. `pip install smolagents` without the search extra.","commonSituations":"Fresh installs without extras, CI environments with trimmed dependencies, or migration from the deprecated `duckduckgo_search` package to `ddgs` after a smolagents upgrade.","solutions":["pip install ddgs (or pip install 'smolagents[search]' if using extras).","Pin/verify the dependency in requirements.txt or pyproject so CI installs it.","If ddgs is installed but still failing, check you're not in a different virtualenv than the one running the code."],"exampleFix":"# before\ntool = DuckDuckGoSearchTool()  # ImportError\n# after\n# pip install ddgs\ntool = DuckDuckGoSearchTool()","handlingStrategy":"validation","validationCode":"try:\n    import ddgs  # noqa\nexcept ImportError:\n    raise SystemExit('pip install ddgs before using DuckDuckGoSearchTool')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Install optional search extras up front: pip install 'smolagents[search]'.","Check importability in entrypoint scripts before building agents."],"tags":["dependency","import-error","search-tool","smolagents"],"backgroundTag":"missing-optional-dependency","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}