Skip to content

The agent engineering platform.

Add context to an output parsing error on Pydantic schema to improve exception handling (#7344)

Manuel Saelices01dca1e438f5
diff --git a/langchain/output_parsers/pydantic.py b/langchain/output_parsers/pydantic.py
index 52619dd493..eacee30e11 100644
--- a/langchain/output_parsers/pydantic.py
+++ b/langchain/output_parsers/pydantic.py
@@ -28,7 +28,7 @@ class PydanticOutputParser(BaseOutputParser[T]):
except (json.JSONDecodeError, ValidationError) as e:
name = self.pydantic_object.__name__
msg = f"Failed to parse {name} from completion {text}. Got: {e}"
- raise OutputParserException(msg)
+ raise OutputParserException(msg, llm_output=text)
def get_format_instructions(self) -> str:
schema = self.pydantic_object.schema()