AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

ExperimentalMarkdownSyntaxTextSplitter Silently Discards Content From Unclosed Code Blocks

ExperimentalMarkdownSyntaxTextSplitter drops all content inside and after an unclosed Markdown code block because _resolve_code_chunk returns an empty string when no closing fence is found, causing silent data loss.

highConfidence 97%Langchain-Text-SplittersVector StoresChat ModelsAgentsAffected V0.3.8

Origin Analysis

In langchain_text_splitters/markdown.py, the _resolve_code_chunk method accumulates lines in chunk but returns "" when it fails to find a closing code fence. This discards the entire accumulated content instead of preserving it.
1. Install langchain-text-splitters 0.3.8.\n2. Run: splitter = ExperimentalMarkdownSyntaxTextSplitter(); text = '# Header\n\nSome text before code.\n\n```python\ndef hello():\n print("world")\n\nMore text after the unclosed code block.\n'; chunks = splitter.split_text(text).\n3. Observe output contains only 'Some text before code.' and loses all content from the unclosed code block onward.

Fixing Code Block

Edge Case Audit

This change alters the output for malformed Markdown: previously empty chunks may now contain large text blocks. Downstream code that expects an empty string for unclosed code blocks could be affected. The method is pure and has no concurrency issues, but splitting very large unclosed code blocks may increase memory usage. To roll back, revert the final return to return \"\". Add regression tests for unclosed fences and ensure the version is bumped after merging.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state