Skip to content

The agent engineering platform.

langchain[patch]: In HTMLHeaderTextSplitter set default encoding to utf-8 (#16372)

i-w-a95ee69a30162
diff --git a/libs/langchain/langchain/text_splitter.py b/libs/langchain/langchain/text_splitter.py
index cd6204adfc..c4ece25320 100644
--- a/libs/langchain/langchain/text_splitter.py
+++ b/libs/langchain/langchain/text_splitter.py
@@ -598,7 +598,9 @@ class HTMLHeaderTextSplitter:
"Unable to import lxml, please install with `pip install lxml`."
) from e
# use lxml library to parse html document and return xml ElementTree
- parser = etree.HTMLParser()
+ # Explicitly encoding in utf-8 allows non-English
+ # html files to be processed without garbled characters
+ parser = etree.HTMLParser(encoding="utf-8")
tree = etree.parse(file, parser)
# document transformation for "structure-aware" chunking is handled with xsl.