Skip to content

fix(langgraph): validate node outputs against State schema before checkpointing#6512

Open
Sidharth Rajmohan (dumko2001) wants to merge 1 commit into
langchain-ai:mainfrom
dumko2001:fix/invalid-state-checkpoint
Open

fix(langgraph): validate node outputs against State schema before checkpointing#6512
Sidharth Rajmohan (dumko2001) wants to merge 1 commit into
langchain-ai:mainfrom
dumko2001:fix/invalid-state-checkpoint

Conversation

@dumko2001

Copy link
Copy Markdown
Contributor

Description:
This PR adds output validation to StateGraph nodes to prevent invalid state from corrupting checkpoints.

Previously, StateGraph validated inputs but allowed nodes to return data that violated the State schema (e.g., returning None for a List[str] field). This invalid data would be saved to the checkpoint, causing a ValidationError only when attempting to load the thread later, effectively rendering the thread permanently inaccessible.

This change injects a validation step in CompiledStateGraph.attach_node. If a Pydantic BaseModel is used as the state schema, node updates are validated using TypeAdapter before being applied. This ensures the run fails fast with a ValidationError rather than persisting corrupt data.

Issue: Fixes #6491

Dependencies: None

Twitter handle: SidharthRajmoh2

This prevents invalid state (e.g. None in a list field) from being saved to the checkpoint, which causes permanent corruption. Validation is now performed in CompiledStateGraph.attach_node for LastValue channels.
@vercel

vercel Bot commented Nov 27, 2025

Copy link
Copy Markdown

Sidharth Rajmohan (@dumko2001) is attempting to deploy a commit to the LangChain Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-issue-check Maintainer override: skip issue-link enforcement external

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid state saved to checkpoint without validation, causing permanent corruption.

2 participants