run-llama/llama_index · error · ImportError
bs4 is required to read HTML files.
Error message
bs4 is required to read HTML files.
What it means
Error "bs4 is required to read HTML files." thrown in run-llama/llama_index.
Source
Thrown at llama-index-core/llama_index/core/node_parser/file/html.py:76
nodes: Sequence[BaseNode],
show_progress: bool = False,
**kwargs: Any,
) -> List[BaseNode]:
all_nodes: List[BaseNode] = []
nodes_with_progress = get_tqdm_iterable(nodes, show_progress, "Parsing nodes")
for node in nodes_with_progress:
nodes = self.get_nodes_from_node(node)
all_nodes.extend(nodes)
return all_nodes
def get_nodes_from_node(self, node: BaseNode) -> List[TextNode]:
"""Get nodes from document."""
try:
from bs4 import BeautifulSoup, Tag
except ImportError:
raise ImportError("bs4 is required to read HTML files.")
text = node.get_content(metadata_mode=MetadataMode.NONE)
soup = BeautifulSoup(text, "html.parser")
html_nodes = []
last_tag = None
current_section = ""
tags = soup.find_all(self.tags)
for tag in tags:
tag_text = self._extract_text_from_tag(tag)
if isinstance(tag, Tag) and (tag.name == last_tag or last_tag is None):
last_tag = tag.name
current_section += f"{tag_text.strip()}\n"
else:
# Skip empty sections (e.g. a container tag whose only children
# are themselves extracted tags) to avoid emitting blank nodes.
if current_section.strip():
html_nodes.append(View on GitHub (pinned to afd0fef371)
Solutions
- Install beautifulsoup4: `pip install bs4`.
- Use a different node parser that does not require bs4 for this input.
When it happens
Trigger: Thrown at llama-index-core/llama_index/core/node_parser/file/html.py:76 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/6f7f24bbf05dc859.
Report an issue: GitHub.