[PR #372] [CLOSED] fix: 🐛 Fix get_graph method by coercing any to typing.Any in StateGraph instantiation #1417

Closed
opened 2026-02-20 17:44:40 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/langgraph/pull/372
Author: @kenichinakanishi
Created: 4/30/2024
Status: Closed

Base: mainHead: fix/get_graph


📝 Commits (1)

  • 4faea51 fix: 🐛 Fix get_graph method by coercing any to typing.Any in StateGraph instantiation

📊 Changes

1 file changed (+35 additions, -2 deletions)

View changed files

📝 langgraph/graph/state.py (+35 -2)

📄 Description

Description:

This pull request addresses an issue with the get_graph method where it fails to create the graph due to the presence of any in the type annotations of the TypedDict schema passed to langgraph.graph.state.StateGraph class. The problem arises because Pydantic, which is used for model creation, does not support any as a valid type annotation.

To resolve this issue, a new method _coerce_types has been introduced in the langgraph.graph.state.StateGraph class. This method recursively traverses the type annotations of the given schema and replaces any occurrences of any with typing.Any. It handles generic types like Dict, List, Tuple, etc., and their nested structures.

The _coerce_types method is called during the instantiation of the StateGraph class, specifically in the __init__ method. It takes the schema parameter and returns a coerced version of the schema with any replaced by typing.Any. This ensures that the type annotations are compatible with Pydantic's model creation process.

Here's a summary of the changes made in this pull request:

  • Added the _coerce_types method to the StateGraph class to coerce any to typing.Any in type annotations.
  • Modified the __init__ method of the StateGraphclass to call _coerce_types on the schema parameter.
  • Updated the type annotations in the StateGraphclass to use typing.Any instead of any.

By making these changes, the get_graph method should now work correctly, allowing the creation of the graph without encountering the any type annotation issue.

Related Issue

Fixes issue https://github.com/langchain-ai/langgraph/issues/347


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/langgraph/pull/372 **Author:** [@kenichinakanishi](https://github.com/kenichinakanishi) **Created:** 4/30/2024 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/get_graph` --- ### 📝 Commits (1) - [`4faea51`](https://github.com/langchain-ai/langgraph/commit/4faea514305d1914fd7189ea6838507edb0661ac) fix: :bug: Fix get_graph method by coercing any to typing.Any in StateGraph instantiation ### 📊 Changes **1 file changed** (+35 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `langgraph/graph/state.py` (+35 -2) </details> ### 📄 Description ## Description: This pull request addresses an issue with the `get_graph` method where it fails to create the graph due to the presence of `any` in the type annotations of the `TypedDict` schema passed to `langgraph.graph.state.StateGraph` class. The problem arises because Pydantic, which is used for model creation, does not support any as a valid type annotation. To resolve this issue, a new method _coerce_types has been introduced in the `langgraph.graph.state.StateGraph` class. This method recursively traverses the type annotations of the given schema and replaces any occurrences of `any` with `typing.Any`. It handles generic types like `Dict`, `List`, `Tuple`, etc., and their nested structures. The `_coerce_types` method is called during the instantiation of the `StateGraph` class, specifically in the `__init__` method. It takes the `schema` parameter and returns a coerced version of the `schema` with `any` replaced by `typing.Any`. This ensures that the type annotations are compatible with Pydantic's model creation process. Here's a summary of the changes made in this pull request: * Added the `_coerce_types` method to the `StateGraph` class to coerce `any` to `typing.Any` in type annotations. * Modified the `__init__` method of the `StateGraph`class to call `_coerce_types` on the schema parameter. * Updated the type annotations in the `StateGraph`class to use `typing.Any` instead of `any`. By making these changes, the `get_graph` method should now work correctly, allowing the creation of the graph without encountering the `any` type annotation issue. ### Related Issue Fixes issue https://github.com/langchain-ai/langgraph/issues/347 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-20 17:44:40 -05:00
yindo closed this issue 2026-02-20 17:44:40 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#1417