AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Dumps()/Dumpd() Raise TypeError For Dict With "Lc" Key And Non-JSON-Native Value

langchain_core.load.dumps() and dumpd() fail when a dict contains a key named "lc" (e.g. locale or language code) and any value in that dict is not JSON-serializable (e.g. datetime). The escape logic added in #34455 wraps the entire dict without serializing its values, leaving raw objects that json.dumps cannot handle.

highConfidence 92%Langchain-CoreVector StoresEmbeddingsAffected V1.5.5

Origin Analysis

In langchain_core/load/_validation.py, _serialize_value detects any dict with an 'lc' key and immediately wraps it as {'__lc_escaped__': obj} without recursively serializing its values. Meanwhile, dumpd() relies on _serialize_value to produce a JSON-serializable dict, and dumps() calls json.dumps on that dict without a default= fallback. Non-JSON-native values inside the escaped dict are never converted, causing TypeError.
1. Import datetime and langchain_core.load.dump.dumps. 2. Create data = {'lc': 'en', 'indexed_at': datetime.datetime(2024, 1, 1)}. 3. Call dumps(data). 4. Observe TypeError: Object of type datetime is not JSON serializable. 5. Compare with data_ok = {'lang': 'en', 'indexed_at': datetime.datetime(2024, 1, 1)}; dumps(data_ok) works.

Fixing Code Block

Edge Case Audit

This change makes serialization of dicts with an 'lc' key lossy for their non-JSON-native values, consistent with how other dicts are handled. It may alter round-trip behavior: deserializing an escaped dict will not reconstruct the original Python object (e.g., datetime becomes a placeholder). No concurrency or thread-safety concerns: the function is pure and stateless. Rollback: revert the single line change in _serialize_value to restore previous behavior. Users who rely on dumpd returning raw objects inside lc-escaped dicts will need to adjust.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state