Skip to content

TypedDict values are rejected by type checkers for Store.put()/aput() despite being valid at runtime #8616

Description

@navarra-lisandro

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangGraph (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Related Issues / PRs

No response

Reproduction Steps / Example Code (Python)

from typing import TypedDict
from langgraph.store.memory import InMemoryStore

class Prefs(TypedDict):
    theme: str

store = InMemoryStore()
value: Prefs = {"theme": "dark"}
store.put(("users", "123"), "prefs", value)

Error Message and Stack Trace (if applicable)

repro.py:9: error: Argument 3 to "put" of "BaseStore" has incompatible type "Prefs"; expected "dict[str, Any]"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

Description

  • I'm trying to use the langgraph library's Store.put()/aput() to store a TypedDict value (a well-typed, string-keyed mapping matching the store's own requirements).
  • I expect the call to type-check cleanly with mypy, since a TypedDict is exactly the kind of typed, JSON-serializable payload the store expects.
  • Instead, mypy rejects it with the error shown below, because value is typed as dict[str, Any], which requires full mutability (arbitrary keys can be added/removed/overwritten) that a TypedDict doesn't support. This breaks type-checking in CI for any caller passing a TypedDict to store.put()/aput(), despite the code working correctly at runtime.

Proposed fix: widen the value parameter on BaseStore.put()/aput() (and PutOp.value) from dict[str, Any] to collections.abc.Mapping[str, Any]. This is a compatible widening (plain dicts still satisfy Mapping[str, Any]) so it doesn't change behavior or break existing callers.

System Info

langgraph-checkpoint: 4.2.0
Python 3.14.5, Darwin

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinginternal

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions