_serialize_value() — langchain Function Reference
Architecture documentation for the _serialize_value() function in _validation.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 12e29989_c05d_0426_3212_cc4e68daaa88["_serialize_value()"] 1b9f9aae_21a8_0928_76d1_c2f1609b2193["_validation.py"] 12e29989_c05d_0426_3212_cc4e68daaa88 -->|defined in| 1b9f9aae_21a8_0928_76d1_c2f1609b2193 d5caf201_e072_55dd_f795_53d30216643e["_serialize_lc_object()"] d5caf201_e072_55dd_f795_53d30216643e -->|calls| 12e29989_c05d_0426_3212_cc4e68daaa88 d5caf201_e072_55dd_f795_53d30216643e["_serialize_lc_object()"] 12e29989_c05d_0426_3212_cc4e68daaa88 -->|calls| d5caf201_e072_55dd_f795_53d30216643e a6efc3e4_8615_15fb_8826_e87e03fb01b4["_needs_escaping()"] 12e29989_c05d_0426_3212_cc4e68daaa88 -->|calls| a6efc3e4_8615_15fb_8826_e87e03fb01b4 ee21e68d_7342_3899_6f61_c1a38e682b18["_escape_dict()"] 12e29989_c05d_0426_3212_cc4e68daaa88 -->|calls| ee21e68d_7342_3899_6f61_c1a38e682b18 style 12e29989_c05d_0426_3212_cc4e68daaa88 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/load/_validation.py lines 69–102
def _serialize_value(obj: Any) -> Any:
"""Serialize a value with escaping of user dicts.
Called recursively on kwarg values to escape any plain dicts that could be confused
with LC objects.
Args:
obj: The value to serialize.
Returns:
The serialized value with user dicts escaped as needed.
"""
if isinstance(obj, Serializable):
# This is an LC object - serialize it properly (not escaped)
return _serialize_lc_object(obj)
if isinstance(obj, dict):
if not all(isinstance(k, (str, int, float, bool, type(None))) for k in obj):
# if keys are not json serializable
return to_json_not_implemented(obj)
# Check if dict needs escaping BEFORE recursing into values.
# If it needs escaping, wrap it as-is - the contents are user data that
# will be returned as-is during deserialization (no instantiation).
# This prevents re-escaping of already-escaped nested content.
if _needs_escaping(obj):
return _escape_dict(obj)
# Safe dict (no 'lc' key) - recurse into values
return {k: _serialize_value(v) for k, v in obj.items()}
if isinstance(obj, (list, tuple)):
return [_serialize_value(item) for item in obj]
if isinstance(obj, (str, int, float, bool, type(None))):
return obj
# Non-JSON-serializable object (datetime, custom objects, etc.)
return to_json_not_implemented(obj)
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does _serialize_value() do?
_serialize_value() is a function in the langchain codebase, defined in libs/core/langchain_core/load/_validation.py.
Where is _serialize_value() defined?
_serialize_value() is defined in libs/core/langchain_core/load/_validation.py at line 69.
What does _serialize_value() call?
_serialize_value() calls 3 function(s): _escape_dict, _needs_escaping, _serialize_lc_object.
What calls _serialize_value()?
_serialize_value() is called by 1 function(s): _serialize_lc_object.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free