#11738·langchainjs

bug(core): RunnableSequence.batch forwards failed inputs to later steps with returnExceptions

Author: To3akaRinCreated Sep 27, 2026Updated Sep 27, 2026

Checked other resources

  • Reproduced against current main at 5d509ad4b8a5ed9dd4b83020b4c103ac8a69859c (@langchain/core 1.2.13).
  • Checked the RunnableSequence API reference and the source contract for batch(..., { returnExceptions: true }).
  • Searched existing issues and open pull requests for RunnableSequence, returnExceptions, and batch error handling. The open RunnableWithFallbacks fixes concern a different class.

Example Code

typescript
import { RunnableLambda } from "@langchain/core/runnables";

const originalError = new Error("validation failed");
const downstreamInputs: unknown[] = [];

const validate = RunnableLambda.from((input: string) => {
  if (input === "bad") throw originalError;
  return input;
});
const processInput = RunnableLambda.from((input: unknown) => {
  downstreamInputs.push(input);
  return "processed";
});

const results = await validate.pipe(processInput).batch(
  ["ok", "bad"],
  {},
  { returnExceptions: true }
);

console.log(results);
console.log(results[1] === originalError);
console.log(downstreamInputs.length);

Actual output:

[ 'processed', 'processed' ]
false
2

Expected: the second result is the original error, and only "ok" reaches processInput.

Description

With returnExceptions: true, RunnableSequence.batch() forwards the errors returned by a step's batch directly into the next step as ordinary inputs. A later step can replace the original error with a successful value, throw a different error, or perform work for an input whose earlier step failed. Invoking each input through the sequence separately stops at the failed step.

The sequence should keep each failed input's original error at its original index and run subsequent step batches only for successful inputs. Per-input configuration and callback parentage must stay aligned after filtering. Failed root runs should emit an error callback, and successful root runs should receive their own output. If every input fails, later steps should not run.

I am preparing a focused fix with regressions for failures at different steps, configuration/callback alignment, all-failed batches, falsy outputs, batching, and concurrency limits. The default fail-fast path will retain its existing behavior.

System Info

  • macOS arm64
  • Node.js 24
  • pnpm 10.14.0
  • @langchain/core 1.2.13 / source revision above
  • No model provider or external credentials required to reproduce

Source: langchain-ai/langchainjs