langchain - 💡(How to fix) Fix ExperimentalMarkdownSyntaxTextSplitter silently drops all content after an unterminated code fence [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

ExperimentalMarkdownSyntaxTextSplitter._resolve_code_chunk returns "" when a markdown code fence is never closed, after consuming the rest of the input. As a result split_text silently discards the code block and every following section and its body — with no error or warning. This is easy to hit with truncated LLM output (cut at max_tokens mid code block), a truncated stream, or a malformed file, which RAG pipelines feed straight into the header splitter.

Error Message

ExperimentalMarkdownSyntaxTextSplitter._resolve_code_chunk returns "" when a markdown code fence is never closed, after consuming the rest of the input. As a result split_text silently discards the code block and every following section and its body — with no error or warning. This is easy to hit with truncated LLM output (cut at max_tokens mid code block), a truncated stream, or a malformed file, which RAG pipelines feed straight into the header splitter.

Error Message and Stack Trace (if applicable)

No error — the content is silently dropped.

Root Cause

ExperimentalMarkdownSyntaxTextSplitter._resolve_code_chunk returns "" when a markdown code fence is never closed, after consuming the rest of the input. As a result split_text silently discards the code block and every following section and its body — with no error or warning. This is easy to hit with truncated LLM output (cut at max_tokens mid code block), a truncated stream, or a malformed file, which RAG pipelines feed straight into the header splitter.

Fix Action

Fixed

Code Example

from langchain_text_splitters.markdown import ExperimentalMarkdownSyntaxTextSplitter as S
md = "# Title\nintro\n\n
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title.
  • I searched the LangChain issues and did not find a duplicate.
  • This is reproducible on the latest langchain-text-splitters.

Package (Required)

  • langchain-text-splitters

Description

ExperimentalMarkdownSyntaxTextSplitter._resolve_code_chunk returns "" when a markdown code fence is never closed, after consuming the rest of the input. As a result split_text silently discards the code block and every following section and its body — with no error or warning. This is easy to hit with truncated LLM output (cut at max_tokens mid code block), a truncated stream, or a malformed file, which RAG pipelines feed straight into the header splitter.

Example Code

from langchain_text_splitters.markdown import ExperimentalMarkdownSyntaxTextSplitter as S
md = "# Title\nintro\n\n```python\nx = 1\n\n## Important Section\ncritical content\n"
[d.page_content for d in S().split_text(md)]
# -> ['# Title\nintro\n\n']   (the code block AND "Important Section" are gone)

Error Message and Stack Trace (if applicable)

No error — the content is silently dropped.

Expected behavior

Content after the unterminated fence (the code block and the following ## Important Section) should be preserved, not silently discarded.

System Info

langchain-text-splitters (latest). A one-line fix plus a regression test is ready in #37964.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Content after the unterminated fence (the code block and the following ## Important Section) should be preserved, not silently discarded.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING