Registry /
llm-agents / langchain-text-splitters
Install & Compatibility
Where this runs
tested against v1.1.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 1.302s · 69.1MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 7.4s · import 1.210s · 78MB
72MB installed
● package 72MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
RecursiveCharacterTextSplitter
✓ from langchain_text_splitters import RecursiveCharacterTextSplitter
✗ from langchain.text_splitter import RecursiveCharacterTextSplitter
Text splitters were moved to a dedicated package. Old `langchain.text_splitter` imports are deprecated or removed.
CharacterTextSplitter
✓ from langchain_text_splitters import CharacterTextSplitter
MarkdownHeaderTextSplitter
✓ from langchain_text_splitters import MarkdownHeaderTextSplitter
Demonstrates the basic usage of the `RecursiveCharacterTextSplitter`, the most commonly recommended text splitter. It shows how to initialize the splitter with `chunk_size` and `chunk_overlap`, and then split a long string into smaller text chunks.
from langchain_text_splitters import RecursiveCharacterTextSplitter
# Example long text
long_text = (
"LangChain is a framework designed to simplify the creation of applications using large language models. "
"It provides tools for chaining together different components, making it easier to build complex LLM workflows. "
"Text splitting is a fundamental step in processing long documents for LLMs, ensuring that chunks fit within context windows and maintain semantic coherence. "
"The RecursiveCharacterTextSplitter is often the recommended default for general-purpose text."
)
# Initialize the splitter
# chunk_size: maximum size of each chunk (in characters by default)
# chunk_overlap: number of characters to overlap between consecutive chunks
text_splitter = RecursiveCharacterTextSplitter(
chunk_size=100,
chunk_overlap=20
)
# Split the text
chunks = text_splitter.split_text(long_text)
# Print the chunks
for i, chunk in enumerate(chunks):
print(f"Chunk {i+1}:\n{chunk}\n---")
Debug
Known issues
breakingThe text splitter modules have been moved from `langchain.text_splitter` to the standalone `langchain-text-splitters` package. Direct imports from `langchain.text_splitter` will no longer work.fixUpdate all text splitter imports from `from langchain.text_splitter import ...` to `from langchain_text_splitters import ...`.
affects: <1.0.0 (old LangChain) to >=1.0.0 (new LangChain/langchain-text-splitters)
gotchaWhen using `create_documents()` method, it expects a *list* of strings (or `Document` objects). Passing a single string will result in each character being treated as a separate document.fixFor a single string, use `text_splitter.split_text(your_string)`. If you intend to pass multiple strings to `create_documents`, ensure they are wrapped in a list: `text_splitter.create_documents([your_string])`.
affects: All versions
gotchaThe `chunk_size` parameter for character-based splitters specifies the *target* maximum chunk size. Due to the splitter's logic (e.g., trying to split on specific separators first), the actual chunk length may not be exactly `chunk_size`.fixUnderstand that `chunk_size` is a guideline. For more precise length control (e.g., token-based), consider `TokenTextSplitter` or custom `length_function` with an appropriate tokenizer.
affects: All versions
gotchaMixing major versions of LangChain ecosystem packages (e.g., `langchain-text-splitters==1.x.x` with `langchain-core==0.3.x`) can lead to compatibility issues and unexpected behavior.fixAlways strive to keep all `langchain-` prefixed packages within the same major version series (e.g., all `1.x.x` or all `0.3.x`) to ensure compatibility.
affects: All versions where major versions of LangChain packages diverge
gotchaSome specialized splitters, like `MarkdownHeaderTextSplitter` and `HTMLHeaderTextSplitter`, do not inherit from the base `TextSplitter` class. This means they might have slightly different method signatures or expectations.fixAlways consult the specific documentation or API reference for specialized text splitters to understand their unique behavior and interfaces.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'langchain.text_splitter' OR ImportError: cannot import name 'RecursiveCharacterTextSplitter' from 'langchain.text_splitter'
The `RecursiveCharacterTextSplitter` and other text splitters have been moved from the `langchain` package to the dedicated `langchain_text_splitters` package as part of LangChain's modularization.
fixFirst, ensure `langchain-text-splitters` is installed: `pip install -U langchain-text-splitters`. Then, update your import statement: `from langchain_text_splitters import RecursiveCharacterTextSplitter`.
ModuleNotFoundError: No module named 'langchain_text_splitters'
The `langchain-text-splitters` package, which contains the text splitting utilities, has not been installed in your Python environment.
fixInstall the package using pip: `pip install langchain-text-splitters`.
AttributeError: module 'langchain.text_splitter' has no attribute 'RecursiveCharacterTextSplitter'
This error occurs when an older version of LangChain is installed, or the `langchain-text-splitters` package is not correctly referenced, leading to the `RecursiveCharacterTextSplitter` class not being found in the `langchain.text_splitter` module.
fixEnsure you have `langchain-text-splitters` installed and are importing from the correct module: `pip install -U langchain-text-splitters` and then `from langchain_text_splitters import RecursiveCharacterTextSplitter`.
ImportError: cannot import name 'RegexTextSplitter' from 'langchain.text_splitter'
The `RegexTextSplitter` class has been deprecated and its functionality is now integrated into `RecursiveCharacterTextSplitter` using the `is_separator_regex` parameter.
fixUse `RecursiveCharacterTextSplitter` and set `is_separator_regex=True` with your regular expression separators: `from langchain_text_splitters import RecursiveCharacterTextSplitter; text_splitter = RecursiveCharacterTextSplitter(separators=[r'\n\n', r'\n'], is_separator_regex=True)`.
Upgrade
Version history
1.1.2latest on PyPI · released Apr 16, 2026
Audit
Dependencies
langchain-corerequiredCore utilities and interfaces for LangChain components.