State schema
A state schema names the data that moves through the graph. Every node reads the current state and normally returns only the keys it changed.1
Tiny example
Section titled “Tiny example”from typing_extensions import TypedDict
class RefundState(TypedDict): order_id: str eligible: bool reason: str
def check_policy(state: RefundState) -> dict: return {"eligible": True, "reason": "Returned within 30 days"}check_policy does not need to return order_id; LangGraph applies its partial update to the existing state.
| Schema choice | Use it when |
|---|---|
TypedDict |
You want a light, typed dictionary |
dataclass |
You need defaults and a Python object |
| Pydantic model | You need recursive input validation and accept extra overhead |
Failure note
Section titled “Failure note”TypedDict helps type checkers; it is not runtime validation. Keep secrets and large service clients out of state. State may be serialized into checkpoints.
Related
Section titled “Related”Footnotes
Section titled “Footnotes”-
LangChain, Graph API overview. ↩