Skip to content

AddableDict silently drops data on type-incompatible merge (langchain_core.runnables.utils) #38850

Description

@Shital24650

Submission checklist

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

No response

Reproduction Steps / Example Code (Python)

from langchain_core.runnables.utils import AddableDict

a = AddableDict({"count": 1})
b = AddableDict({"count": "some_string"})
result = a + b
print(result)

Error Message and Stack Trace (if applicable)

No error is raised. This is the bug — the operation should either succeed correctly or raise a clear error, but instead it silently produces incorrect output with no indication anything went wrong.

Description

I'm using AddableDict (langchain_core.runnables.utils), which is used internally
in RunnablePassthrough and LCEL's streaming/chunk-aggregation path.

I expect merging two AddableDict instances with a type-incompatible value at the
same key to either merge correctly or raise a clear error.

Instead, add and radd catch TypeError internally and silently fall back
to the right-hand value, discarding the left-hand value with no warning:

try:
    added = chunk[key] + other[key]
except TypeError:
    added = other[key]
chunk[key] = added

In the reproduction above, the int 1 is silently lost and replaced by the string,
with no exception or log. Since AddableDict is used in real chain output
aggregation, this could cause silent data loss whenever streamed/merged chunks
have mismatched types at the same key — a caller has no way to know data was dropped.

Suggested fix: raise a clear error instead of silently discarding data, e.g.:

except TypeError as e:
    raise TypeError(
        f"Cannot add incompatible types for key '{key}': "
        f"{type(chunk[key])} and {type(other[key])}"
    ) from e

System Info

System Information

OS: Linux
OS Version: #1 SMP PREEMPT_DYNAMIC Dmitri Iouchtchenko (@0)
Python Version: 3.12.3 (main, Mar 3 2026, 12:15:18) [GCC 13.3.0]

Package Information

langchain_core: 1.4.9
langsmith: 0.10.3
langchain_protocol: 0.0.18

Other Dependencies

anyio: 4.14.2
distro: 1.9.0
httpx: 0.28.1
jsonpatch: 1.33
orjson: 3.11.9
packaging: 26.0
pydantic: 2.13.4
pyyaml: 6.0.3
requests: 2.33.1
requests-toolbelt: 1.0.0
sniffio: 1.3.1
tenacity: 9.1.4
typing-extensions: 4.15.0
uuid-utils: 0.17.0
websockets: 16.1
wrapt: 2.1.2
xxhash: 3.8.1
zstandard: 0.25.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugRelated to a bug, vulnerability, unexpected error with an existing featurecore`langchain-core` package issues & PRsexternal

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions