Skip to content

core: Cleanup Pydantic models and handle deprecation warnings #30799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cbornet
Copy link
Collaborator

@cbornet cbornet commented Apr 12, 2025

  • Simplified Pydantic handling since Pydantic v1 is not supported anymore.
  • Replace use of deprecated v1 methods by corresponding v2 methods.
  • Remove use of other deprecated methods.
  • Activate mypy errors on deprecated methods use.

Copy link

vercel bot commented Apr 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Apr 23, 2025 9:07am

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. 🤖:nit Small modifications/deletions, fixes, deps or improvements to existing code or docs labels Apr 12, 2025
@cbornet cbornet force-pushed the pydantic-cleanup branch 3 times, most recently from 7529366 to 5fcb2bb Compare April 12, 2025 01:11
@cbornet cbornet requested a review from eyurtsev April 12, 2025 01:12
@cbornet cbornet force-pushed the pydantic-cleanup branch 3 times, most recently from 14905a4 to 6b9bb2c Compare April 13, 2025 15:10
@@ -183,6 +122,9 @@ def pre_init(func: Callable) -> Any:
with warnings.catch_warnings():
warnings.filterwarnings(action="ignore", category=PydanticDeprecationWarning)

# Ideally we would use @model_validator(mode="before") but this would change the
# order of the validators. See https://github.com/pydantic/pydantic/discussions/7434.
# So we keep root_validator for backward compatibility.
Copy link
Collaborator Author

@cbornet cbornet Apr 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One possibility would be to deprecate pre_init and create a new decorator, for instance before_init, that uses model_validator.
WDYT ?

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Apr 13, 2025
@sydney-runkle
Copy link
Collaborator

I would love to drop v1 support (would clean up the codebase a lot). Need to chat with the team about this depending on download #s, etc.

@cbornet
Copy link
Collaborator Author

cbornet commented Apr 18, 2025

Note: LangChain already dropped support for Pydantic v1. There remains some models using pydantic.v1 namespace of Pydantic v2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:nit Small modifications/deletions, fixes, deps or improvements to existing code or docs size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants