From 8dffedebd6da1e7e9f2ad424c2979cd2f749fbea Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Wed, 7 Aug 2024 11:38:28 -0400 Subject: [PATCH] Add Skip Validation() --- libs/core/langchain_core/output_parsers/pydantic.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/core/langchain_core/output_parsers/pydantic.py b/libs/core/langchain_core/output_parsers/pydantic.py index e129a7f28f8..76ac4dc2632 100644 --- a/libs/core/langchain_core/output_parsers/pydantic.py +++ b/libs/core/langchain_core/output_parsers/pydantic.py @@ -1,10 +1,11 @@ import json -from typing import Generic, List, Type +from typing import Generic, List, Optional, Type, Annotated import pydantic # pydantic: ignore from langchain_core.exceptions import OutputParserException from langchain_core.output_parsers import JsonOutputParser +from pydantic import SkipValidation from langchain_core.outputs import Generation from langchain_core.utils.pydantic import ( PYDANTIC_MAJOR_VERSION, @@ -15,7 +16,7 @@ from langchain_core.utils.pydantic import ( class PydanticOutputParser(JsonOutputParser, Generic[TBaseModel]): """Parse an output using a pydantic model.""" - pydantic_object: Type[TBaseModel] # type: ignore + pydantic_object: Annotated[Type[TBaseModel], SkipValidation()] # type: ignore """The pydantic model to parse.""" def _parse_obj(self, obj: dict) -> TBaseModel: @@ -105,7 +106,7 @@ class PydanticOutputParser(JsonOutputParser, Generic[TBaseModel]): return self.pydantic_object -PydanticOutputParser.update_forward_refs() +PydanticOutputParser.model_rebuild() _PYDANTIC_FORMAT_INSTRUCTIONS = """The output should be formatted as a JSON instance that conforms to the JSON schema below.