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

HTMLSemanticPreservingSplitter Drops Video/Audio URLs From Nested Source Tags

The splitter fails to extract media URLs from nested <source> elements inside <video> and <audio> tags, resulting in empty Markdown links when preserve_videos or preserve_audio is enabled. This causes data loss for common HTML media patterns.

mediumConfidence 85%LangchainChat ModelsAgentsMemory

Origin Analysis

The media preservation logic only reads the direct `src` attribute of the <video>/<audio> tag and does not fall back to the first child <source> element. According to HTML spec, media sources can be provided either via a direct src attribute or via nested source tags, but the implementation ignores the latter.
Run the provided Python code with HTML containing <video><source src='...'></video> and <audio><source src='...'></audio>, set preserve_videos=True and preserve_audio=True, and observe empty Markdown links like ![video:]() instead of URLs.

Fixing Code Block

--- a/libs/text-splitters/langchain_text_splitters/html.py +++ b/libs/text-splitters/langchain_text_splitters/html.py @@ -100,10 +100,14 @@ if element.name in ["video", "audio"]: if (element.name == "video" and self.preserve_videos) or (element.name == "audio" and self.preserve_audio): src = element.get("src") + if not src: + source_element = element.find("source") + if source_element: + src = source_element.get("src") if src: media_text = f"![{element.name}:{src}]({src})" else: media_text = f"![{element.name}:]()"
Add a fallback to extract the src from the first nested <source> element when the direct src attribute is absent. This aligns with common HTML authoring patterns and ensures the URL is preserved.

Edge Case Audit

This patch picks the first <source> element regardless of its type or order. If multiple <source> tags exist (e.g., different resolutions), it may select a suboptimal URL. In concurrent environments, do not monkey-patch globally; apply the change directly to the library source or use a subclass. Rollback: revert to the original single-line src extraction if unexpected media links appear. The patch does not handle srcset or data-src attributes.

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