Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langchain ai Langgraph Warnings

From Leeroopedia
Attribute Value
Source `libs/langgraph/langgraph/warnings.py` (61 lines)
Domain Core, Deprecation
Principle Deprecation_Management
Library langgraph
Import `from langgraph.warnings import LangGraphDeprecationWarning, LangGraphDeprecatedSinceV10`

Overview

The `warnings.py` module defines the deprecation warning hierarchy for LangGraph. It provides a base `LangGraphDeprecationWarning` class with structured versioning information and two version-specific subclasses (`LangGraphDeprecatedSinceV05` and `LangGraphDeprecatedSinceV10`) that encode the deprecation and expected removal versions.

Description

LangGraph uses a structured deprecation system inspired by Pydantic's `PydanticDeprecationWarning` pattern. Each deprecation warning carries explicit version information about when the deprecation was introduced and when the deprecated functionality is expected to be removed.

`LangGraphDeprecationWarning(DeprecationWarning)` -- The base class for all LangGraph deprecation warnings. It extends Python's built-in `DeprecationWarning` and adds:

  • `message: str` -- The deprecation message (trailing periods are stripped).
  • `since: tuple[int, int]` -- The LangGraph version (major, minor) where the deprecation was introduced.
  • `expected_removal: tuple[int, int]` -- The version where the functionality will be removed. Defaults to the next major version if not specified (i.e., `(since[0] + 1, 0)`).
  • `__str__` -- Produces a formatted message: `"{message}. Deprecated in LangGraph V{major}.{minor} to be removed in V{major}.{minor}."`

`LangGraphDeprecatedSinceV05(LangGraphDeprecationWarning)` -- Convenience subclass for features deprecated since LangGraph v0.5.0. Sets `since=(0, 5)` and `expected_removal=(2, 0)`.

`LangGraphDeprecatedSinceV10(LangGraphDeprecationWarning)` -- Convenience subclass for features deprecated since LangGraph v1.0.0. Sets `since=(1, 0)` and `expected_removal=(2, 0)`.

These warning classes are used throughout the LangGraph codebase (in `constants.py`, `errors.py`, `tool_validator.py`, and elsewhere) to signal deprecated imports and APIs.

Usage

from langgraph.warnings import LangGraphDeprecationWarning, LangGraphDeprecatedSinceV10
from warnings import warn

# Issue a deprecation warning for a feature deprecated in v1.0
warn(
    "my_old_function is deprecated. Use my_new_function instead.",
    LangGraphDeprecatedSinceV10,
    stacklevel=2,
)

Code Reference

LangGraphDeprecationWarning

Attribute Type Description
`message` `str` The deprecation message (trailing period stripped).
`since` `tuple[int, int]` Version where the deprecation was introduced (major, minor).
`expected_removal` `tuple[int, int]` Version where the feature will be removed. Defaults to `(since[0] + 1, 0)`.
Method Signature Description
`__init__` `(message, *args, since, expected_removal=None)` Initialize with message and version info.
`__str__` `() -> str` Format message with version information.

Version-Specific Subclasses

Class `since` `expected_removal` Description
`LangGraphDeprecatedSinceV05` `(0, 5)` `(2, 0)` Deprecated since LangGraph v0.5.0.
`LangGraphDeprecatedSinceV10` `(1, 0)` `(2, 0)` Deprecated since LangGraph v1.0.0.

I/O Contract

Aspect Detail
Input A deprecation message string and optional version parameters.
Output A `DeprecationWarning` subclass instance with formatted version information.
Side Effects When passed to `warnings.warn`, these warnings are displayed according to Python's warning filter settings. By default, `DeprecationWarning` is shown only to developers (not in `__main__` module unless filters are configured).

Usage Examples

Creating a Custom Deprecation Warning

from langgraph.warnings import LangGraphDeprecationWarning

warning = LangGraphDeprecationWarning(
    "old_api is deprecated",
    since=(0, 8),
    expected_removal=(1, 0),
)
print(str(warning))
# "old_api is deprecated. Deprecated in LangGraph V0.8 to be removed in V1.0."

Using V10 Deprecation in Library Code

from warnings import warn
from langgraph.warnings import LangGraphDeprecatedSinceV10

def old_function():
    warn(
        "old_function is deprecated. Use new_function instead",
        LangGraphDeprecatedSinceV10,
        stacklevel=2,
    )
    return new_function()

Default expected_removal Behavior

from langgraph.warnings import LangGraphDeprecationWarning

# When expected_removal is not specified, it defaults to the next major version
w = LangGraphDeprecationWarning("test", since=(1, 3))
print(w.expected_removal)
# (2, 0)

w2 = LangGraphDeprecationWarning("test", since=(0, 5))
print(w2.expected_removal)
# (1, 0)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment