graphiti icon indicating copy to clipboard operation
graphiti copied to clipboard

šŸ› [Bug] PydanticUserError — Should use typing_extensions.TypedDict on Python 3.10+

Open MumuTW opened this issue 6 months ago • 2 comments

šŸ“‹ Description

When running graphiti_mcp_server.py (or any module in this monorepo) in a Python 3.10 environment, I encountered a PydanticUserError related to TypedDict imports.

PydanticUserError: Please use typing_extensions.TypedDict instead of typing.TypedDict on Python < 3.12.

This happens because Pydantic 2.x requires TypedDict implementations that provide richer metadata for schema generation, which is only fully supported in the typing module for Python >= 3.12. For earlier Python versions, typing_extensions.TypedDict must be used.

šŸ” Environment

  • Python Version: 3.10.x
  • Pydantic Version: 2.x
  • Operating System: macOS

āœ… Expected Behavior

  • All TypedDict usage should consistently import from typing_extensions for Python < 3.12
  • No runtime errors when generating Pydantic models or OpenAPI schemas
  • Cross-version compatibility should work seamlessly

āŒ Actual Behavior

  • Multiple locations in the codebase use incompatible imports:
    from typing import TypedDict
    
    

Pydantic fails during schema generation with the above error Server cannot start properly in Python 3.10/3.11 environments

šŸ”„ Steps to Reproduce

  1. Set up Python 3.10 environment
  2. Install dependencies including Pydantic 2.x
  3. Run graphiti_mcp_server.py
  4. Observe the PydanticUserError

Example traceback:

pydantic.errors.PydanticUserError: Please use typing_extensions.TypedDict instead of typing.TypedDict on Python < 3.12.

Find all problematic imports:

bashgrep -rn "from typing import.*TypedDict" .

šŸ’” Proposed Solution

  1. Global Import Replacement:
# Replace this
from typing import TypedDict

# With this
from typing_extensions import TypedDict
  1. Dependency Management: Ensure typing_extensions is explicitly listed in requirements Add version constraints if needed

  2. Prevention: Add a pre-commit hook or linting rule to catch future typing.TypedDict usage Consider adding a comment in code style guidelines

šŸ”§ Additional Context

The typing_extensions package is already a standard dependency for multi-version Python support and provides the necessary TypedDict implementation that Pydantic expects.

šŸ“ Acceptance Criteria

  • [ ] All typing.TypedDict imports replaced with typing_extensions.TypedDict
  • [ ] Server runs successfully on Python 3.10+
  • [ ] No Pydantic schema generation errors
  • [ ] typing_extensions added to requirements if missing
  • [ ] Optional: Prevention mechanism added to avoid regression

✨ Benefit

Ensures full compatibility for all supported Python versions as declared.

Thanks for your awesome work! I’m happy to open a PR if you prefer!

MumuTW avatar Jul 14 '25 12:07 MumuTW

@MumuTW Is this still an issue? Please confirm within 14 days or this issue will be closed.

claude[bot] avatar Oct 05 '25 00:10 claude[bot]

@MumuTW Is this still an issue? Please confirm within 14 days or this issue will be closed.

claude[bot] avatar Nov 17 '25 00:11 claude[bot]