The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
Harrison/json new line (#4646)
Harrison Chasef5e2f701156f
diff --git a/langchain/output_parsers/pydantic.py b/langchain/output_parsers/pydantic.pyindex 4b0fa53d54..52619dd493 100644--- a/langchain/output_parsers/pydantic.py+++ b/langchain/output_parsers/pydantic.py@@ -22,7 +22,7 @@ class PydanticOutputParser(BaseOutputParser[T]):json_str = ""if match:json_str = match.group()- json_object = json.loads(json_str)+ json_object = json.loads(json_str, strict=False)return self.pydantic_object.parse_obj(json_object)except (json.JSONDecodeError, ValidationError) as e:diff --git a/tests/unit_tests/output_parsers/test_pydantic_parser.py b/tests/unit_tests/output_parsers/test_pydantic_parser.pyindex aefd3c0a79..8c12049960 100644--- a/tests/unit_tests/output_parsers/test_pydantic_parser.py+++ b/tests/unit_tests/output_parsers/test_pydantic_parser.py@@ -21,6 +21,7 @@ class TestModel(BaseModel):additional_fields: Optional[str] = Field(description="Additional fields", default=None)+ for_new_lines: str = Field(description="To be used to test newlines")# Prevent pytest from trying to run tests on TestModel@@ -30,7 +31,8 @@ TestModel.__test__ = False # type: ignore[attr-defined]DEF_RESULT = """{"action": "Update","action_input": "The PydanticOutputParser class is powerful",- "additional_fields": null+ "additional_fields": null,+ "for_new_lines": "not_escape_newline:\n escape_newline: \\n"}"""# action 'update' with a lowercase 'u' to test schema validation failure.@@ -44,6 +46,7 @@ DEF_EXPECTED_RESULT = TestModel(action=Actions.UPDATE,action_input="The PydanticOutputParser class is powerful",additional_fields=None,+ for_new_lines="not_escape_newline:\n escape_newline: \n",)