
- Improves reliability by preventing missing keys and type mismatches.
- Increases explainability by making the data surface explicit.
- Enables safer collaboration between nodes and teams.
- Makes observability and debugging easier because tools can inspect well-known fields.


TypedDict (or typing_extensions.TypedDict for older versions). This provides a contract between nodes and allows static type checkers like mypy to catch inconsistencies early.
Example TypedDict schema:
- Using
total=Falsemakes keys optional by default. Alternatively, usetotal=Trueand mark selective keys withNotRequired(see PEP 655)—choose the pattern that best fits your project. chat_historyis typed asList[BaseMessage](LangChain message types) to preserve conversational context.tool_resultsis a flexibleDict[str, Any]because outputs differ between integrations.
- Static typing and
TypedDictlet tools verify nodes read/write the correct keys and types. - Observability systems can record which fields exist at each node execution to simplify debugging and audits.
- A typed schema clarifies expectations across teams and over time, improving maintainability.
Example usage pattern
Design your schema to be permissive early (optional fields) and grow it intentionally as new nodes or tools are added. This balances development speed with safety and observability.
- Define the schema early in the project to reduce ambiguity and accidental overwrites.
- Treat the schema as a living contract: extend it when you add tools, nodes, or new observability needs.
- Use loop counters and explicit success/error flags to make iterative or cyclical graphs safe and auditable.
- Prefer clear, well-documented keys over deep opaque blobs—this improves explainability and cross-team collaboration.
- Leverage static analysis (
mypy) and runtime checks in critical nodes to catch unexpected types or missing keys early.
- When you add new nodes or tool integrations that need new fields.
- When data flows change, require additional metadata, or new observability signals.
- As part of routine maintenance: keep the schema aligned with runtime telemetry and logs.


- Python
TypedDictdocs: https://docs.python.org/3/library/typing.html#typing.TypedDict - PEP 655 (optional keys): https://peps.python.org/pep-0655/
- mypy static type checker: https://mypy-lang.org/
- LangChain message types: https://python.langchain.com/en/latest/