[PR #298] [MERGED] Pregel: Add support for falsy outputs in Pregel class #1364

Closed
opened 2026-02-20 17:44:33 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/langgraph/pull/298
Author: @hmasdev
Created: 4/11/2024
Status: Merged
Merged: 4/11/2024
Merged by: @nfcampos

Base: mainHead: feature-handle-falsy-output


📝 Commits (3)

  • 42de330 Add support for allow_falsy_output parameter in Pregel class
  • 236ecb1 rename node name in tests
  • 46e67cf Remove flag

📊 Changes

4 files changed (+39 additions, -17 deletions)

View changed files

📝 langgraph/pregel/__init__.py (+7 -9)
📝 langgraph/pregel/io.py (+6 -8)
📝 tests/test_pregel.py (+13 -0)
📝 tests/test_pregel_async.py (+13 -0)

📄 Description

Description

This PR addresses a specific issue where a graph unexpectedly returns None for falsy values instead of the actual falsy output. This behavior was identified during operations where the expected behavior is to output falsy values, such as 0, False, or an empty collection, but instead, the graph outputs None.

The issue is illustrated with the following example:

Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from langchain_core.runnables import RunnableLambda
>>> from langgraph.graph import Graph, END
>>> workflow = Graph()
>>> workflow.add_node('minus1', RunnableLambda(lambda n: n-1))
>>> workflow.set_entry_point('minus1')
>>> workflow.add_edge('minus1', END)
>>> runnable = workflow.compile()
>>> print(runnable.invoke(1))
None
>>> print(runnable.invoke(2))
1
>>> print(runnable.invoke(-1))
-2

For more details, refer to https://github.com/langchain-ai/langchain/discussions/20201 .

The solution implemented in this PR introduces a new parameter allow_falsy_output to decide whether the graph should return None or the actual output when the result is falsy. This allows for more accurate output representation, as demonstrated below:

>>> print(runnable.invoke(1, allow_falsy_output=True))
0

Issues

https://github.com/langchain-ai/langchain/discussions/20201

Dependencies

Nothing

Question

The purpose of the following if statements in the langgraph/pregel/__init__.py file is unclear:

Could someone provide clarity on the intention behind these conditions?


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/langgraph/pull/298 **Author:** [@hmasdev](https://github.com/hmasdev) **Created:** 4/11/2024 **Status:** ✅ Merged **Merged:** 4/11/2024 **Merged by:** [@nfcampos](https://github.com/nfcampos) **Base:** `main` ← **Head:** `feature-handle-falsy-output` --- ### 📝 Commits (3) - [`42de330`](https://github.com/langchain-ai/langgraph/commit/42de3304dcb619f2b20def34373f57a57dede182) Add support for allow_falsy_output parameter in Pregel class - [`236ecb1`](https://github.com/langchain-ai/langgraph/commit/236ecb1982084af73e46faec851b347930b3c8c1) rename node name in tests - [`46e67cf`](https://github.com/langchain-ai/langgraph/commit/46e67cff87d2502c3da7383e0f7fac07df8346ed) Remove flag ### 📊 Changes **4 files changed** (+39 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `langgraph/pregel/__init__.py` (+7 -9) 📝 `langgraph/pregel/io.py` (+6 -8) 📝 `tests/test_pregel.py` (+13 -0) 📝 `tests/test_pregel_async.py` (+13 -0) </details> ### 📄 Description ## Description This PR addresses a specific issue where a graph unexpectedly returns None for falsy values instead of the actual falsy output. This behavior was identified during operations where the expected behavior is to output falsy values, such as 0, False, or an empty collection, but instead, the graph outputs None. The issue is illustrated with the following example: ```python Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from langchain_core.runnables import RunnableLambda >>> from langgraph.graph import Graph, END >>> workflow = Graph() >>> workflow.add_node('minus1', RunnableLambda(lambda n: n-1)) >>> workflow.set_entry_point('minus1') >>> workflow.add_edge('minus1', END) >>> runnable = workflow.compile() >>> print(runnable.invoke(1)) None >>> print(runnable.invoke(2)) 1 >>> print(runnable.invoke(-1)) -2 ``` For more details, refer to https://github.com/langchain-ai/langchain/discussions/20201 . The solution implemented in this PR introduces a new parameter allow_falsy_output to decide whether the graph should return None or the actual output when the result is falsy. This allows for more accurate output representation, as demonstrated below: ```python >>> print(runnable.invoke(1, allow_falsy_output=True)) 0 ``` ## Issues https://github.com/langchain-ai/langchain/discussions/20201 ## Dependencies Nothing ## Question The purpose of the following if statements in the langgraph/pregel/__init__.py file is unclear: - https://github.com/langchain-ai/langgraph/blob/114137059350b95068db9e96f79924fdc379bbe2/langgraph/pregel/__init__.py#L701 - https://github.com/langchain-ai/langgraph/blob/114137059350b95068db9e96f79924fdc379bbe2/langgraph/pregel/__init__.py#L706 - https://github.com/langchain-ai/langgraph/blob/114137059350b95068db9e96f79924fdc379bbe2/langgraph/pregel/__init__.py#L915 - https://github.com/langchain-ai/langgraph/blob/114137059350b95068db9e96f79924fdc379bbe2/langgraph/pregel/__init__.py#L920 Could someone provide clarity on the intention behind these conditions? --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-20 17:44:33 -05:00
yindo closed this issue 2026-02-20 17:44:33 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#1364