_dump_pydantic_models() — langchain Function Reference
Architecture documentation for the _dump_pydantic_models() function in dump.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 5cbc4686_165a_f32c_5474_0a55a2f6b29d["_dump_pydantic_models()"] a51258b9_512f_dc1c_b25c_dc1d97b3a5d8["dump.py"] 5cbc4686_165a_f32c_5474_0a55a2f6b29d -->|defined in| a51258b9_512f_dc1c_b25c_dc1d97b3a5d8 46e40d05_c4e1_f364_4649_1ff3401a3e37["dumps()"] 46e40d05_c4e1_f364_4649_1ff3401a3e37 -->|calls| 5cbc4686_165a_f32c_5474_0a55a2f6b29d 66a960cf_c531_d600_1a66_6777acc56b51["dumpd()"] 66a960cf_c531_d600_1a66_6777acc56b51 -->|calls| 5cbc4686_165a_f32c_5474_0a55a2f6b29d style 5cbc4686_165a_f32c_5474_0a55a2f6b29d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/load/dump.py lines 43–67
def _dump_pydantic_models(obj: Any) -> Any:
"""Convert nested Pydantic models to dicts for JSON serialization.
Handles the special case where a `ChatGeneration` contains an `AIMessage`
with a parsed Pydantic model in `additional_kwargs["parsed"]`. Since
Pydantic models aren't directly JSON serializable, this converts them to
dicts.
Args:
obj: The object to process.
Returns:
A copy of the object with nested Pydantic models converted to dicts, or
the original object unchanged if no conversion was needed.
"""
if (
isinstance(obj, ChatGeneration)
and isinstance(obj.message, AIMessage)
and (parsed := obj.message.additional_kwargs.get("parsed"))
and isinstance(parsed, BaseModel)
):
obj_copy = obj.model_copy(deep=True)
obj_copy.message.additional_kwargs["parsed"] = parsed.model_dump()
return obj_copy
return obj
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does _dump_pydantic_models() do?
_dump_pydantic_models() is a function in the langchain codebase, defined in libs/core/langchain_core/load/dump.py.
Where is _dump_pydantic_models() defined?
_dump_pydantic_models() is defined in libs/core/langchain_core/load/dump.py at line 43.
What calls _dump_pydantic_models()?
_dump_pydantic_models() is called by 2 function(s): dumpd, dumps.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free