The graph incorrectly obtained the input schema #188

Closed
opened 2026-02-20 17:30:56 -05:00 by yindo · 2 comments
Owner

Originally created by @gbaian10 on GitHub (Aug 13, 2024).

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph/LangChain 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 LangGraph/LangChain rather than my code.
  • I am sure this is better as an issue rather than a GitHub discussion, since this is a LangGraph bug and not a design question.

Example Code

from langchain_core.runnables import RunnableConfig
from langgraph.graph import MessagesState, StateGraph


def foo(state: MessagesState) -> MessagesState:
    print(f"foo: {state}")
    return {"messages": "foo"}


def error1(state, config: RunnableConfig) -> MessagesState:
    # It read the first type_hint,
    # thus incorrectly obtaining the type_hint of the `config` variable.
    print(f"error1: {state}")
    return {"messages": "this is config"}


def error2(state, config) -> MessagesState:
    # It actually obtained the type_hint of the `return`,
    # which just happened to be the same as the `state`.
    print(f"error2: {state}")
    return {"messages": "this is return"}


graph = StateGraph(MessagesState)
graph.add_node(foo)
graph.add_node(error1)
graph.add_node(error2)

graph.set_entry_point("foo")
graph.add_edge("foo", "error1")
graph.add_edge("error1", "error2")
graph.set_finish_point("error2")

graph = graph.compile()
graph.invoke({"messages": "Hello"})

Error Message and Stack Trace (if applicable)

foo: {'messages': [HumanMessage(content='Hello', id='d00c79c6-3c77-4a1b-8e68-806334f1dd36')]}

error1: {'tags': None, 'metadata': None, 'callbacks': None, 'run_name': None, 'max_concurrency': None, 'recursion_limit': None, 'configurable': None, 'run_id': None}

error2: {'messages': [HumanMessage(content='Hello', id='d00c79c6-3c77-4a1b-8e68-806334f1dd36'), HumanMessage(content='foo', id='6ac49f5c-e8be-4d93-a5e0-bcce19cf9ca3'), HumanMessage(content='this is config', id='91bc0d28-3095-4d27-a667-0bb0aab09123')]}

Description

When using add_node, if the func of the action has an incomplete type_hint (e.g., only config type_hint or return type_hint), unexpected results may occur.

image

The reason is that when there is at least one type_hint, it always reads the first one type_hint, but this type_hint may not be the type_hint of the state variable.

System Info

langgraph==0.2.3
langchain_core==0.2.30

platform==windows
python_version==3.12.5

Originally created by @gbaian10 on GitHub (Aug 13, 2024). ### Checked other resources - [X] I added a very descriptive title to this issue. - [X] I searched the [LangGraph](https://langchain-ai.github.io/langgraph/)/LangChain documentation with the integrated search. - [X] I used the GitHub search to find a similar question and didn't find it. - [X] I am sure that this is a bug in LangGraph/LangChain rather than my code. - [X] I am sure this is better as an issue [rather than a GitHub discussion](https://github.com/langchain-ai/langgraph/discussions/new/choose), since this is a LangGraph bug and not a design question. ### Example Code ```python from langchain_core.runnables import RunnableConfig from langgraph.graph import MessagesState, StateGraph def foo(state: MessagesState) -> MessagesState: print(f"foo: {state}") return {"messages": "foo"} def error1(state, config: RunnableConfig) -> MessagesState: # It read the first type_hint, # thus incorrectly obtaining the type_hint of the `config` variable. print(f"error1: {state}") return {"messages": "this is config"} def error2(state, config) -> MessagesState: # It actually obtained the type_hint of the `return`, # which just happened to be the same as the `state`. print(f"error2: {state}") return {"messages": "this is return"} graph = StateGraph(MessagesState) graph.add_node(foo) graph.add_node(error1) graph.add_node(error2) graph.set_entry_point("foo") graph.add_edge("foo", "error1") graph.add_edge("error1", "error2") graph.set_finish_point("error2") graph = graph.compile() graph.invoke({"messages": "Hello"}) ``` ### Error Message and Stack Trace (if applicable) ```shell foo: {'messages': [HumanMessage(content='Hello', id='d00c79c6-3c77-4a1b-8e68-806334f1dd36')]} error1: {'tags': None, 'metadata': None, 'callbacks': None, 'run_name': None, 'max_concurrency': None, 'recursion_limit': None, 'configurable': None, 'run_id': None} error2: {'messages': [HumanMessage(content='Hello', id='d00c79c6-3c77-4a1b-8e68-806334f1dd36'), HumanMessage(content='foo', id='6ac49f5c-e8be-4d93-a5e0-bcce19cf9ca3'), HumanMessage(content='this is config', id='91bc0d28-3095-4d27-a667-0bb0aab09123')]} ``` ### Description When using `add_node`, if the func of the `action` has an incomplete type_hint (e.g., only config type_hint or return type_hint), unexpected results may occur. ![image](https://github.com/user-attachments/assets/d706c6a3-0f60-486e-9b07-12c3899e983e) The reason is that when there is at least one type_hint, it always reads the first one type_hint, but this type_hint may not be the type_hint of the `state` variable. ### System Info langgraph==0.2.3 langchain_core==0.2.30 platform==windows python_version==3.12.5
yindo closed this issue 2026-02-20 17:30:56 -05:00
Author
Owner

@nfcampos commented on GitHub (Aug 13, 2024):

Thanks for reporting! Your fix looks good, do you mind adding the snippet above as a test case?

@nfcampos commented on GitHub (Aug 13, 2024): Thanks for reporting! Your fix looks good, do you mind adding the snippet above as a test case?
Author
Owner

@gbaian10 commented on GitHub (Aug 13, 2024):

Thanks for reporting! Your fix looks good, do you mind adding the snippet above as a test case?

Sure, it would be great if you could help add these tests.
I'm not very familiar with your test case, and I'm not even sure where the test code should be placed. (./lib/langgraph/tests/test_state.py) ?

@gbaian10 commented on GitHub (Aug 13, 2024): > Thanks for reporting! Your fix looks good, do you mind adding the snippet above as a test case? Sure, it would be great if you could help add these tests. I'm not very familiar with your test case, and I'm not even sure where the test code should be placed. (./lib/langgraph/tests/test_state.py) ?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#188