{"record":{"id":"e3e8d93b76a82d11","repo":"huggingface/smolagents","slug":"you-must-install-packages-markdownify-and-reque","errorCode":null,"errorMessage":"You must install packages `markdownify` and `requests` to run this tool: for instance run `pip install markdownify requests`.","messagePattern":"You must install packages `markdownify` and `requests` to run this tool: for instance run `pip install markdownify requests`\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"src/smolagents/default_tools.py","lineNumber":523,"sourceCode":"        super().__init__()\n        self.max_output_length = max_output_length\n\n    def _truncate_content(self, content: str, max_length: int) -> str:\n        if len(content) <= max_length:\n            return content\n        return (\n            content[:max_length] + f\"\\n..._This content has been truncated to stay below {max_length} characters_...\\n\"\n        )\n\n    def forward(self, url: str) -> str:\n        try:\n            import re\n\n            import requests\n            from markdownify import markdownify\n            from requests.exceptions import RequestException\n        except ImportError as e:\n            raise ImportError(\n                \"You must install packages `markdownify` and `requests` to run this tool: for instance run `pip install markdownify requests`.\"\n            ) from e\n        try:\n            # Send a GET request to the URL with a 20-second timeout\n            response = requests.get(url, timeout=20)\n            response.raise_for_status()  # Raise an exception for bad status codes\n\n            # Convert the HTML content to Markdown\n            markdown_content = markdownify(response.text).strip()\n\n            # Remove multiple line breaks\n            markdown_content = re.sub(r\"\\n{3,}\", \"\\n\\n\", markdown_content)\n\n            return self._truncate_content(markdown_content, self.max_output_length)\n\n        except requests.exceptions.Timeout:\n            return \"The request timed out. Please try again later or check the URL.\"\n        except RequestException as e:","sourceCodeStart":505,"sourceCodeEnd":541,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/default_tools.py#L505-L541","documentation":"Raised by VisitWebPageTool.forward when markdownify or requests cannot be imported. The tool fetches a URL and converts HTML to markdown, both optional dependencies, so it raises ImportError (chained from the underlying failure) instead of degrading silently.","triggerScenarios":"Calling visit_webpage.run(url) in an environment lacking markdownify or requests. The import happens inside forward, so construction succeeds and the error only appears on first use.","commonSituations":"Base smolagents install without extras, lean Docker images, CI caching that drops optional deps after a smolagents upgrade.","solutions":["pip install markdownify requests (or the relevant smolagents extras).","Add both to your project's pinned dependencies so environments stay reproducible.","Verify with `python -c \"import markdownify, requests\"` in the same environment that runs the agent."],"exampleFix":"# before\nvisit_webpage.run('https://example.com')  # ImportError\n# after\n# pip install markdownify requests\nvisit_webpage.run('https://example.com')","handlingStrategy":"validation","validationCode":"try:\n    import markdownify, requests  # noqa\nexcept ImportError:\n    raise SystemExit('pip install markdownify requests')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Install extras when adding web tools to an agent.","Dependency-check at app startup, since the tool imports lazily inside forward()."],"tags":["dependency","import-error","web-tool","smolagents"],"backgroundTag":"missing-optional-dependency","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}