Add Skip Validation()

This commit is contained in:
Eugene Yurtsev
2024-08-07 11:38:28 -04:00
parent 60adf8d6e4
commit 8dffedebd6

View File

@@ -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.