the case of inheritance and in the case of passing objects to LangChain.Example 1: Extending via inheritanceYES from pydantic.v1 import root_validator, validatorclass CustomTool(BaseTool): # BaseTool is v1 code    x: int = Field(default=1)    def _run(*args, **kwargs):        return "hello"    @validator('x') # v1 code    @classmethod    def validate_x(cls, x: int) -> int:        return 1    CustomTool(    name='custom_tool',    description="hello",    x=1,)Mixing Pydantic v2 primitives with Pydantic v1 primitives can raise cryptic errorsNO from pydantic import Field, field_validator # pydantic v2class CustomTool(BaseTool): # BaseTool is v1 code    x: int = Field(default=1)    def _run(*args, **kwargs):        return "hello"    @field_validator('x') # v2 code    @classmethod    def validate_x(cls, x: int) -> int:        return 1    CustomTool(     name='custom_tool',    description="hello",    x=1,)Example 2: Passing objects to LangChainYESfrom langchain.tools.base import Toolfrom pydantic.v1 import BaseModel, Field # <-- Uses v1 namespaceclass CalculatorInput(BaseModel):    question: str = Field()Tool.from_function( # <-- tool uses v1 namespace    func=lambda question: 'hello',    name="Calculator",    description="useful for when you need to answer questions about math",    args_schema=CalculatorInput)NOfrom langchain.tools.base import Toolfrom pydantic import BaseModel, Field # <-- Uses v2 namespaceclass CalculatorInput(BaseModel):    question: str = Field()Tool.from_function( # <-- tool uses v1 namespace    func=lambda question: 'hello',    name="Calculator",    description="useful for when you need to answer questions about math",    args_schema=CalculatorInput)PreviousQA with private data protectionNextSafetyLangChain Pydantic migration planCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.
- Pydantic v2 was released in June, 2023 (https://docs.pydantic.dev/2.0/blog/pydantic-v2-final/)
- Pydantic v2 was released in June, 2023 (https://docs.pydantic.dev/2.0/blog/pydantic-v2-final/) ->: the case of inheritance and in the case of passing objects to LangChain.Example 1: Extending via inheritanceYES from pydantic.v1 import root_validator, validatorclass CustomTool(BaseTool): # BaseTool is v1 code    x: int = Field(default=1)    def _run(*args, **kwargs):        return "hello"    @validator('x') # v1 code    @classmethod    def validate_x(cls, x: int) -> int:        return 1    CustomTool(    name='custom_tool',    description="hello",    x=1,)Mixing Pydantic v2 primitives with Pydantic v1 primitives can raise cryptic errorsNO from pydantic import Field, field_validator # pydantic v2class CustomTool(BaseTool): # BaseTool is v1 code    x: int = Field(default=1)    def _run(*args, **kwargs):        return "hello"    @field_validator('x') # v2 code    @classmethod    def validate_x(cls, x: int) -> int:        return 1    CustomTool(     name='custom_tool',    description="hello",    x=1,)Example 2: Passing objects to LangChainYESfrom langchain.tools.base import Toolfrom pydantic.v1 import BaseModel, Field # <-- Uses v1 namespaceclass CalculatorInput(BaseModel):    question: str = Field()Tool.from_function( # <-- tool uses v1 namespace    func=lambda question: 'hello',    name="Calculator",    description="useful for when you need to answer questions about math",    args_schema=CalculatorInput)NOfrom langchain.tools.base import Toolfrom pydantic import BaseModel, Field # <-- Uses v2 namespaceclass CalculatorInput(BaseModel):    question: str = Field()Tool.from_function( # <-- tool uses v1 namespace    func=lambda question: 'hello',    name="Calculator",    description="useful for when you need to answer questions about math",    args_schema=CalculatorInput)PreviousQA with private data protectionNextSafetyLangChain Pydantic migration planCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.