kmail.at
contact

elsewhere

EnglishEN
← learning

langchain · difficulty ◆

dict() is Deprecated: Switch to asdict()

A one-line migration that keeps mypy happy and your code forward-compatible.

Stop calling .dict() before it disappears. asdict() is the one-word fix that keeps your serialization code clean and mypy quiet.

fully AI-generatedThis text is fully AI-generated and was published without human editorial review.

2026-06-09 · 5 min read

$ grep -rn "\.dict()" --include="*.py" .
langchain-core 1.4.2
Release
#31685
PR

Deprecation of .dict()

One line
Migration

sed can do it

What it does

LangChain v1.4.2 deprecates the .dict() method across all LangChain objects (Runnable, Message, Tool, etc.) in favor of .asdict(). The old .dict() conflicted with Python’s builtin dict type annotation, causing confusion and type-checking issues in static analysis tools like mypy.

Why it matters

If you use .dict() to serialize LangChain objects (Messages, Runnable configs, tool outputs), your code will break once the deprecation period ends. Migrating to .asdict() is a one-line change with identical output, but you must update before the removal lands in a future release.

Example

$ Migrate a message serialization call
{'id': 'msg-123', 'content': 'Hello world', 'additional_kwargs': {},
 'response_metadata': {}, 'type': 'ai', 'usage': None}

msg.asdict() returns the same shape that msg.dict() used to.

$ Inspect a Runnable config
dict_keys(['id', 'lc', 'name', 'kwargs'])

chain.asdict() works across Runnable objects too.

Common flags

.asdict()
The new method replacing deprecated .dict() everywhere
--deprecation
Old .dict() still works for now but warns and will be removed

History

Origin

The deprecation was introduced in langchain-core==1.4.2 (PR #31685), surfaced in the June 9 tutorial.

Why now

The conflict with the builtin dict annotation broke type inference and confused tooling, so the team standardized on asdict() across the whole codebase.

Under the hood

Static typing benefits

Because asdict() no longer collides with the dict builtin, mypy and IDE type checkers can resolve serialization calls precisely, catching mistakes at edit time instead of runtime.

Fun facts

Pros & cons

pros

  • + Removes a name clash with the dict builtin
  • + Identical output, trivial migration
  • + Better static-analysis ergonomics

cons

  • − Old code keeps working until removal
  • − Large codebases need a sweep

Takeaways

  1. 1Replace .dict() with .asdict() for identical output.
  2. 2A grep + sed sweep plus your test suite is a complete migration.
  3. 3Do it before the deprecation is removed to avoid breakage.

Related commands

archive entry — written and published by a scheduled job, never editorially reviewed. Kept for reference: out of the site’s search index, and no ads run here. the reviewed library →

← all learning