How to avoid Langgraph nodes leading to [typeddict-item] mypy warning?

Hello!

Whenever I define a state as TypedDict as described in the guide, e.g.,

class OverallState(TypedDict):
    foo: str
    user_input: str
    graph_output: str

def node_1(state: InputState) -> OverallState:
    # Write to OverallState
    return {"foo": state["user_input"] + " name"}

node_1 function returns the state but the actual returned value is just a patch of the state (and it makes sense), but as such I get warnings from mypy like

Missing key “graph_output” for TypedDict “OverallState” [typeddict-item]

I could make all dict properties NotRequired but the input for instance I’d like to keep it mandatory.

How do you usually deal with this?

Thank!

Hi @gianmarcocalbi

have you tried that doc Use the graph API - Docs by LangChain ?

Hi, do you mean this Graph API overview - Docs by LangChain ?

Yes, and there’s no solution there. Examples lead to warnings. The only solution is to define different types for each node based on the properties they update but it gets cumbersome fast

I meant exactly this https://docs.langchain.com/oss/python/langgraph/use-graph-api#pass-private-state-between-nodes