huggingface/smolagents · error · ImportError
You must install packages `markdownify` and `requests` to ru
Error message
You must install packages `markdownify` and `requests` to run this tool: for instance run `pip install markdownify requests`.
What it means
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.
Source
Thrown at src/smolagents/default_tools.py:523
super().__init__()
self.max_output_length = max_output_length
def _truncate_content(self, content: str, max_length: int) -> str:
if len(content) <= max_length:
return content
return (
content[:max_length] + f"\n..._This content has been truncated to stay below {max_length} characters_...\n"
)
def forward(self, url: str) -> str:
try:
import re
import requests
from markdownify import markdownify
from requests.exceptions import RequestException
except ImportError as e:
raise ImportError(
"You must install packages `markdownify` and `requests` to run this tool: for instance run `pip install markdownify requests`."
) from e
try:
# Send a GET request to the URL with a 20-second timeout
response = requests.get(url, timeout=20)
response.raise_for_status() # Raise an exception for bad status codes
# Convert the HTML content to Markdown
markdown_content = markdownify(response.text).strip()
# Remove multiple line breaks
markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content)
return self._truncate_content(markdown_content, self.max_output_length)
except requests.exceptions.Timeout:
return "The request timed out. Please try again later or check the URL."
except RequestException as e:View on GitHub (pinned to 30bb116109)
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.
Example fix
# before
visit_webpage.run('https://example.com') # ImportError
# after
# pip install markdownify requests
visit_webpage.run('https://example.com') Defensive patterns
Strategy: validation
Validate before calling
try:
import markdownify, requests # noqa
except ImportError:
raise SystemExit('pip install markdownify requests') Prevention
- Install extras when adding web tools to an agent.
- Dependency-check at app startup, since the tool imports lazily inside forward().
When it happens
Trigger: 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.
Common situations: Base smolagents install without extras, lean Docker images, CI caching that drops optional deps after a smolagents upgrade.
Understand the failure class
Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.
Related errors
- You must install package `ddgs` to run this tool: for instan
- You must install `wikipedia-api` to run this tool: for insta
- Error during jinja template rendering: {type(e).__name__}: {
- Cannot specify both 'messages' and 'steps' parameters. Use '
- The 'system_prompt' property is read-only. Use 'self.prompt_
AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28).
Data as JSON: /api/errors/e3e8d93b76a82d11.
Report an issue: GitHub.