Default value of state variable not working with reducer function #745

Open
opened 2026-02-20 17:41:33 -05:00 by yindo · 8 comments
Owner

Originally created by @minki-j on GitHub (Jun 27, 2025).

Checked other resources

  • This is a bug, not a usage question. For questions, please use GitHub Discussions.
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

def extend_list(original: list, new: list):
    original.extend(new)
    return original

OverallState(BaseModel):
    variable: Annotated[list[str], extend_list] = Field(default_factory=lambda: ["default"])

Error Message and Stack Trace (if applicable)


Description

When I set default value for a state variable that has Annotated with a reducer function, the default value is not applied.

System Info

System Information

OS: Darwin
OS Version: Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:43 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T8132
Python Version: 3.13.2 (main, Mar 17 2025, 21:26:38) [Clang 20.1.0 ]

Package Information

langchain_core: 0.3.66
langchain: 0.3.26
langsmith: 0.4.2
langchain_anthropic: 0.3.15
langchain_openai: 0.3.25
langchain_text_splitters: 0.3.8
langgraph_sdk: 0.1.70

Optional packages not installed

langserve

Other Dependencies

anthropic<1,>=0.52.0: Installed. No version info available.
async-timeout<5.0.0,>=4.0.0;: Installed. No version info available.
httpx: 0.28.1
httpx>=0.25.2: Installed. No version info available.
jsonpatch<2.0,>=1.33: Installed. No version info available.
langchain-anthropic;: Installed. No version info available.
langchain-aws;: Installed. No version info available.
langchain-azure-ai;: Installed. No version info available.
langchain-cohere;: Installed. No version info available.
langchain-community;: Installed. No version info available.
langchain-core<1.0.0,>=0.3.51: Installed. No version info available.
langchain-core<1.0.0,>=0.3.63: Installed. No version info available.
langchain-core<1.0.0,>=0.3.66: Installed. No version info available.
langchain-deepseek;: Installed. No version info available.
langchain-fireworks;: Installed. No version info available.
langchain-google-genai;: Installed. No version info available.
langchain-google-vertexai;: Installed. No version info available.
langchain-groq;: Installed. No version info available.
langchain-huggingface;: Installed. No version info available.
langchain-mistralai;: Installed. No version info available.
langchain-ollama;: Installed. No version info available.
langchain-openai;: Installed. No version info available.
langchain-perplexity;: Installed. No version info available.
langchain-text-splitters<1.0.0,>=0.3.8: Installed. No version info available.
langchain-together;: Installed. No version info available.
langchain-xai;: Installed. No version info available.
langsmith-pyo3: Installed. No version info available.
langsmith>=0.1.17: Installed. No version info available.
langsmith>=0.3.45: Installed. No version info available.
openai-agents: Installed. No version info available.
openai<2.0.0,>=1.86.0: Installed. No version info available.
opentelemetry-api: Installed. No version info available.
opentelemetry-exporter-otlp-proto-http: Installed. No version info available.
opentelemetry-sdk: Installed. No version info available.
orjson: 3.10.18
orjson>=3.10.1: Installed. No version info available.
packaging: 24.2
packaging<25,>=23.2: Installed. No version info available.
pydantic: 2.11.7
pydantic<3.0.0,>=2.7.4: Installed. No version info available.
pydantic>=2.7.4: Installed. No version info available.
pytest: Installed. No version info available.
PyYAML>=5.3: Installed. No version info available.
requests: 2.32.4
requests-toolbelt: 1.0.0
requests<3,>=2: Installed. No version info available.
rich: Installed. No version info available.
SQLAlchemy<3,>=1.4: Installed. No version info available.
tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available.
tiktoken<1,>=0.7: Installed. No version info available.
typing-extensions>=4.7: Installed. No version info available.
zstandard: 0.23.0

Originally created by @minki-j on GitHub (Jun 27, 2025). ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use GitHub Discussions. - [x] I added a clear and detailed title that summarizes the issue. - [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example). - [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue. ### Example Code ```python def extend_list(original: list, new: list): original.extend(new) return original OverallState(BaseModel): variable: Annotated[list[str], extend_list] = Field(default_factory=lambda: ["default"]) ``` ### Error Message and Stack Trace (if applicable) ```shell ``` ### Description When I set default value for a state variable that has Annotated with a reducer function, the default value is not applied. ### System Info System Information ------------------ > OS: Darwin > OS Version: Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:43 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T8132 > Python Version: 3.13.2 (main, Mar 17 2025, 21:26:38) [Clang 20.1.0 ] Package Information ------------------- > langchain_core: 0.3.66 > langchain: 0.3.26 > langsmith: 0.4.2 > langchain_anthropic: 0.3.15 > langchain_openai: 0.3.25 > langchain_text_splitters: 0.3.8 > langgraph_sdk: 0.1.70 Optional packages not installed ------------------------------- > langserve Other Dependencies ------------------ > anthropic<1,>=0.52.0: Installed. No version info available. > async-timeout<5.0.0,>=4.0.0;: Installed. No version info available. > httpx: 0.28.1 > httpx>=0.25.2: Installed. No version info available. > jsonpatch<2.0,>=1.33: Installed. No version info available. > langchain-anthropic;: Installed. No version info available. > langchain-aws;: Installed. No version info available. > langchain-azure-ai;: Installed. No version info available. > langchain-cohere;: Installed. No version info available. > langchain-community;: Installed. No version info available. > langchain-core<1.0.0,>=0.3.51: Installed. No version info available. > langchain-core<1.0.0,>=0.3.63: Installed. No version info available. > langchain-core<1.0.0,>=0.3.66: Installed. No version info available. > langchain-deepseek;: Installed. No version info available. > langchain-fireworks;: Installed. No version info available. > langchain-google-genai;: Installed. No version info available. > langchain-google-vertexai;: Installed. No version info available. > langchain-groq;: Installed. No version info available. > langchain-huggingface;: Installed. No version info available. > langchain-mistralai;: Installed. No version info available. > langchain-ollama;: Installed. No version info available. > langchain-openai;: Installed. No version info available. > langchain-perplexity;: Installed. No version info available. > langchain-text-splitters<1.0.0,>=0.3.8: Installed. No version info available. > langchain-together;: Installed. No version info available. > langchain-xai;: Installed. No version info available. > langsmith-pyo3: Installed. No version info available. > langsmith>=0.1.17: Installed. No version info available. > langsmith>=0.3.45: Installed. No version info available. > openai-agents: Installed. No version info available. > openai<2.0.0,>=1.86.0: Installed. No version info available. > opentelemetry-api: Installed. No version info available. > opentelemetry-exporter-otlp-proto-http: Installed. No version info available. > opentelemetry-sdk: Installed. No version info available. > orjson: 3.10.18 > orjson>=3.10.1: Installed. No version info available. > packaging: 24.2 > packaging<25,>=23.2: Installed. No version info available. > pydantic: 2.11.7 > pydantic<3.0.0,>=2.7.4: Installed. No version info available. > pydantic>=2.7.4: Installed. No version info available. > pytest: Installed. No version info available. > PyYAML>=5.3: Installed. No version info available. > requests: 2.32.4 > requests-toolbelt: 1.0.0 > requests<3,>=2: Installed. No version info available. > rich: Installed. No version info available. > SQLAlchemy<3,>=1.4: Installed. No version info available. > tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available. > tiktoken<1,>=0.7: Installed. No version info available. > typing-extensions>=4.7: Installed. No version info available. > zstandard: 0.23.0
yindo added the bughelp wanted labels 2026-02-20 17:41:33 -05:00
Author
Owner

@minki-j commented on GitHub (Jun 27, 2025):

Here is Deepwiki's anlaysis on this issue:

https://deepwiki.com/search/when-i-set-default-value-for-a_cd75134c-4404-48e5-a1c1-a25cdda4dd97

@minki-j commented on GitHub (Jun 27, 2025): Here is Deepwiki's anlaysis on this issue: https://deepwiki.com/search/when-i-set-default-value-for-a_cd75134c-4404-48e5-a1c1-a25cdda4dd97
Author
Owner

@minki-j commented on GitHub (Jun 27, 2025):

For those who experience the same issue, here is how to get around this at the moment:

default = ["default_example"]

def extend_list(original: list, new: list):
    if len(original) == 0 and len(new) == 0:
        return default

    original.extend(new)
    return original

When the state is initiated, the reducer function will be triggered with empty lists in this case; You can add the default logic in there.

@minki-j commented on GitHub (Jun 27, 2025): For those who experience the same issue, here is how to get around this at the moment: ```python default = ["default_example"] def extend_list(original: list, new: list): if len(original) == 0 and len(new) == 0: return default original.extend(new) return original ``` When the state is initiated, the reducer function will be triggered with empty lists in this case; You can add the default logic in there.
Author
Owner

@sydney-runkle commented on GitHub (Jun 27, 2025):

Can repro this, thanks for the report! PRs welcome with a fix for this.

@sydney-runkle commented on GitHub (Jun 27, 2025): Can repro this, thanks for the report! PRs welcome with a fix for this.
Author
Owner

@hemhemoh commented on GitHub (Jul 1, 2025):

Hello @sydney-runkle, I would like to work on this.

@hemhemoh commented on GitHub (Jul 1, 2025): Hello @sydney-runkle, I would like to work on this.
Author
Owner

@kailip commented on GitHub (Jul 17, 2025):

Hello. I can confirm that the issue is still there in a newest release of langgraph. Could this issue be re-opened?

@kailip commented on GitHub (Jul 17, 2025): Hello. I can confirm that the issue is still there in a newest release of langgraph. Could this issue be re-opened?
Author
Owner

@chitralputhran commented on GitHub (Jul 31, 2025):

Hi @minki-j @sydney-runkle,

Submitted a PR #5789 that addresses the issue regarding Pydantic default values not working with reducer functions.
Would appreciate your feedback and testing on the PR.

Thanks for reporting this bug!

@chitralputhran commented on GitHub (Jul 31, 2025): Hi @minki-j @sydney-runkle, Submitted a PR #5789 that addresses the issue regarding Pydantic default values not working with reducer functions. Would appreciate your feedback and testing on the PR. Thanks for reporting this bug!
Author
Owner

@hoppiesbunny commented on GitHub (Nov 26, 2025):

+1, bumping this up. could we help to merge the PR in? I'm experiencing this bug too @sydney-runkle @minki-j

@hoppiesbunny commented on GitHub (Nov 26, 2025): +1, bumping this up. could we help to merge the PR in? I'm experiencing this bug too @sydney-runkle @minki-j
Author
Owner

@antoinegar commented on GitHub (Jan 7, 2026):

+1, is there any clean way to set up a default value while using a reducer @sydney-runkle @minki-j?

@antoinegar commented on GitHub (Jan 7, 2026): +1, is there any clean way to set up a default value while using a reducer @sydney-runkle @minki-j?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#745