mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-22 19:09:57 +00:00
langchain.core : Use shallow copy for schema manipulation in JsonOutputParser.get_format_instructions (#17162)
- **Description :** Fix: Use shallow copy for schema manipulation in get_format_instructions Prevents side effects on the original schema object by using a dictionary comprehension for a safer and more controlled manipulation of schema key-value pairs, enhancing code reliability. - **Issue:** #17161 - **Dependencies:** None - **Twitter handle:** None
This commit is contained in:
@@ -29,7 +29,8 @@ class PydanticOutputParser(JsonOutputParser):
|
||||
raise OutputParserException(msg, llm_output=json_object)
|
||||
|
||||
def get_format_instructions(self) -> str:
|
||||
schema = self.pydantic_object.schema()
|
||||
# Copy schema to avoid altering original Pydantic schema.
|
||||
schema = {k: v for k, v in self.pydantic_object.schema().items()}
|
||||
|
||||
# Remove extraneous fields.
|
||||
reduced_schema = schema
|
||||
|
@@ -43,7 +43,8 @@ class YamlOutputParser(BaseOutputParser[T]):
|
||||
raise OutputParserException(msg, llm_output=text) from e
|
||||
|
||||
def get_format_instructions(self) -> str:
|
||||
schema = self.pydantic_object.schema()
|
||||
# Copy schema to avoid altering original Pydantic schema.
|
||||
schema = {k: v for k, v in self.pydantic_object.schema().items()}
|
||||
|
||||
# Remove extraneous fields.
|
||||
reduced_schema = schema
|
||||
|
Reference in New Issue
Block a user