langgraph icon indicating copy to clipboard operation
langgraph copied to clipboard

Pydantic v2 deprecations in langgraph/gregel/_messages.py:104 (__fields__, __fields_set__, instance access of computed fields)

Open dmsthd opened this issue 2 months ago • 2 comments

Checked other resources

  • [x] This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
  • [x] I added a clear and detailed title that summarizes the issue.
  • [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

langgraph/gregel/_messages.py:104

Error Message and Stack Trace (if applicable)

langgraph/gregel/_messages.py:104: pydandictDeprecatedSince20: The `__fields__` attribute is deprecated, use the `model_fields` class property instead. Deprecated in Pydantic v2.0; to be removed in v3.0.

langgraph/gregel/_messages.py:104: pydandictDeprecatedSince20: The `__fields_set__` attribute is deprecated, use the `model_fields_set` class property instead. Deprecated in Pydantic v2.0; to be removed in v3.0.

langgraph/gregel/_messages.py:104:pydandictDeprecatedSince211: Accessing 'model_computed_fields' on the instance is deprecated; access it on the model class. Deprecated in v2.11; to be removed in v3.0.

langgraph/gregel/_messages.py:104:pydandictDeprecatedSince211: Accessing model field metadata on the instance is deprecated; access it on the model class. Deprecated in v2.11; to be removed in v3.0.

Description

I'm using langgraph with Pydantic v2.11 and seeing multiple deprecation warnings coming from internal code, not my own models.

These warnings appear during normal use (e.g., when importing or executing graphs).
They originate from langgraph/gregel/_messages.py:104.

Observed Warnings langgraph/gregel/_messages.py:104: pydandictDeprecatedSince20: The __fields__ attribute is deprecated, use the model_fields class property instead. Deprecated in Pydantic v2.0; to be removed in v3.0.

langgraph/gregel/_messages.py:104: pydandictDeprecatedSince20: The __fields_set__ attribute is deprecated, use the model_fields_set class property instead. Deprecated in Pydantic v2.0; to be removed in v3.0.

langgraph/gregel/_messages.py:104:pydandictDeprecatedSince211: Accessing 'model_computed_fields' on the instance is deprecated; access it on the model class. Deprecated in v2.11; to be removed in v3.0.

langgraph/gregel/_messages.py:104:pydandictDeprecatedSince211: Accessing model field metadata on the instance is deprecated; access it on the model class. Deprecated in v2.11; to be removed in v3.0.

Expected Behavior No Pydantic deprecation warnings when using current versions (>= v2.0).

Notes

  • The issue originates from LangGraph’s internal use of deprecated Pydantic v1-style APIs (__fields__, etc.).
  • I can’t provide a standalone repro since the warning is raised during normal internal graph execution, not user code.

System Info

pydandic: 2.12.3 pydantic-settings:2.11.0 langgraph:1.0.1 langsmith-pyo3: Installed.No version info available.

dmsthd avatar Oct 24 '25 09:10 dmsthd

Thank you for flagging this @dmsthd, looking into it

casparb avatar Nov 07 '25 17:11 casparb

repro:

import warnings
from typing import Annotated

from langchain_core.messages import AIMessage, BaseMessage
from pydantic import BaseModel

from langgraph.graph import StateGraph, START, END
from langgraph.graph.message import add_messages


warnings.simplefilter("always", DeprecationWarning)


class NodeResponse(BaseModel):
    message: BaseMessage
    count: int = 0


class State(BaseModel):
    messages: Annotated[list[BaseMessage], add_messages]


def my_node(state: State) -> NodeResponse:
    return NodeResponse(
        message=AIMessage(content="Hello from the node!"),
        count=1
    )


builder = StateGraph(State)
builder.add_node("my_node", my_node)
builder.add_edge(START, "my_node")
builder.add_edge("my_node", END)

graph = builder.compile()


def main():
    """Run the graph with stream_mode='messages' to trigger warnings."""
    print("Running test to reproduce Pydantic deprecation warnings...")
    print("=" * 70)
    print()

    initial_state = State(messages=[])

    print("Streaming messages (warnings should appear here):")
    print("-" * 70)

    for chunk in graph.stream(initial_state, stream_mode="messages"):
        print(f"Received chunk: {chunk}")

    print()
    print("=" * 70)
    print("Test complete. Check above for deprecation warnings.")
    print()
    print("Expected warnings:")
    print("  - __fields__ is deprecated")
    print("  - __fields_set__ is deprecated")
    print("  - model_computed_fields on instance is deprecated")
    print("  - model field metadata on instance is deprecated")


if __name__ == "__main__":
    main()

casparb avatar Nov 07 '25 18:11 casparb