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

RunnableWithFallbacks.Batch/Abatch Use Zip(Strict=False), Risking Silent Output Misalignment

The batch() and abatch() methods in RunnableWithFallbacks use zip() with strict=False in four places. If the lists of inputs, callback managers, and configs ever diverge in length due to an upstream bug, the zip silently truncates and produces misaligned outputs without raising an error. Switching to strict=True would surface any length mismatch immediately.

mediumConfidence 95%Langchain-CoreAgentsChat ModelsVector StoresAffected V1.3.0a1

Origin Analysis

The use of zip(..., strict=False) (the default) silently truncates to the shortest iterable when lengths differ, masking potential upstream bugs that lead to length mismatches between inputs, callback managers, and configs.
1. Ensure langchain-core 1.3.0a1 is installed. 2. Inspect the source code of langchain_core/runnables/fallbacks.py. 3. Observe four zip() calls in RunnableWithFallbacks.batch() and RunnableWithFallbacks.abatch() use strict=False. 4. Simulate a length mismatch (e.g., by monkeypatching an internal list to have a different length) and run batch(). Notice it completes without error and silently drops or mispairs elements.

Fixing Code Block

# In RunnableWithFallbacks.batch() method: # Change line ~309 from: # for inputs, callbacks in zip(inputs, callbacks, strict=False): # to: # for inputs, callbacks in zip(inputs, callbacks, strict=True): # Change line ~329 from: # for manager, inputs in zip(manager.copy(), inputs, strict=False): # to: # for manager, inputs in zip(manager.copy(), inputs, strict=True): # In RunnableWithFallbacks.abatch() method: # Change line ~406 from: # for inputs, callbacks in zip(inputs, callbacks, strict=False): # to: # for inputs, callbacks in zip(inputs, callbacks, strict=True): # Change line ~428 from: # for manager, inputs in zip(manager.copy(), inputs, strict=False): # to: # for manager, inputs in zip(manager.copy(), inputs, strict=True):
Replacing strict=False with strict=True in all four zip() calls ensures that any length mismatch between the zipped iterables raises a ValueError immediately, eliminating silent truncation and preventing incorrect output alignment.

Edge Case Audit

This change will raise an exception if the internal lists ever have mismatched lengths, which could break existing code that inadvertently relies on silent truncation (though such reliance is unsafe). If users observe new ValueError exceptions after upgrading, they should investigate and fix the upstream length mismatch rather than reverting this change. Rollback is possible by restoring strict=False, but that would reintroduce silent misalignment. The strict parameter requires Python 3.10 or higher; ensure the runtime supports it.

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