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

TypeError In Merge_lists When Merging String And Dict Content Blocks From Mistral Streaming Citations

The `merge_lists` utility in `langchain-core` crashes with `TypeError: string indices must be integers` when merging a list that contains both plain strings and citation dictionaries (with an `index` key). This occurs during streaming of Mistral responses that include inline citations, because `merge_lists` assumes every element is a dictionary.

highConfidence 92%LangchainRetrieversAgentsAffected Vlangchain-Core==1.2.5Affected Vlangchain==1.2.0Affected Vlangchain-Mistralai==1.1.1

Origin Analysis

In `langchain_core/utils/_merge.py`, the `merge_lists` function uses a check like `"index" in e_left` on every list element. For string elements, this is a substring check, not a key existence check. If a string contains the substring `"index"` (e.g., text such as "Please see index 0 for details"), the condition evaluates to `True` and the code then attempts `e_left["index"]`, raising `TypeError`. The function lacks a type guard to skip non-dict elements.
Run the following Python snippet (ensure at least one string contains the substring "index"): ```python from langchain_core.utils._merge import merge_lists merged = [ "start answer... see index 0 for source", {"type": "reference", "index": 0, "reference_ids": ["iKcb2CAQ7"]}, "other answer..." ] other = [{"type": "reference", "index": 0, "reference_ids": ["DGqzzmqc3"]}] result = merge_lists(merged, other) ```

Fixing Code Block

Edge Case Audit

This hotfix is backward-compatible for pure dict lists but changes list-merging semantics for keys other than `reference_ids` (concatenates lists instead of potentially overwriting). If the previous behaviour for such keys was intentional, adjust `_deep_merge_dicts` accordingly. The function is pure and thread-safe, but if multiple streaming chunks contain the same index with conflicting scalar values, the last value wins. To roll back, restore the original `merge_lists` from the installed `langchain-core` version or pin `langchain-core<1.2.5` until an official fix is released.

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