bug(core): RunnableBranch._invoke falls through to default on falsy branch output (0/""/false)
Author: nayan-kunwarCreated Sep 8, 2026Updated Sep 8, 2026
Labelsbug
Checked other resources
- This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
- I added a very descriptive title to this issue.
- I searched the LangChain.js documentation with the integrated search.
- 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.js rather than my code.
- The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
import { RunnableBranch } from "@langchain/core/runnables";
const branch = RunnableBranch.from([ [(x: number) => x > 0, (x: number) => 0], (x: number) => -1, ]); console.log(await branch.invoke(5)); // expected: 0, actual: -1
Error Message and Stack Trace (if applicable)
N/A - no throw, silent wrong routing
Description
- I'm trying to use RunnableBranch where a branch returns 0 / "" / false.
- I expect the matched branch output to be returned.
- Instead libs/langchain-core/src/runnables/branch.ts:170 does
if (!result)so falsy output is discarded and default runs. Same file :236 in _streamIterator correctly usesif (stream === undefined).
System Info
platform: win32 x64 (Windows) Node: v24.6.0 npm: 11.5.1 pnpm: 10.14.0 @langchain/core: 1.2.9 HEAD: 56130def8 chore: version packages (rc) (#11532) File: libs/langchain-core/src/runnables/branch.ts:170
Source: langchain-ai/langchainjs