
    f3fi+              	           d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ d	ed
efdZd	ed
efdZddd	ededed
efdZd	ed
efdZy)a  Serialize LangChain objects to JSON.

Provides `dumps` (to JSON string) and `dumpd` (to dict) for serializing
`Serializable` objects.

## Escaping

During serialization, plain dicts (user data) that contain an `'lc'` key are escaped
by wrapping them: `{"__lc_escaped__": {...original...}}`. This prevents injection
attacks where malicious data could trick the deserializer into instantiating
arbitrary classes. The escape marker is removed during deserialization.

This is an allowlist approach: only dicts explicitly produced by
`Serializable.to_json()` are treated as LC objects; everything else is escaped if it
could be confused with the LC format.
    N)Any)	BaseModel)_serialize_value)Serializableto_json_not_implemented)	AIMessage)ChatGenerationobjreturnc                 X    t        | t              r| j                         S t        |       S )zReturn a default value for an object.

    Args:
        obj: The object to serialize to json if it is a Serializable object.

    Returns:
        A JSON serializable object or a SerializedNotImplemented object.
    )
isinstancer   to_jsonr   r
   s    V/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_core/load/dump.pydefaultr      s%     #|${{}"3''    c                 >   t        | t              rt        | j                  t              rr| j                  j                  j                  d      x}rKt        |t              r;| j                  d      }|j                         |j                  j                  d<   |S | S )a  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.
    parsedT)deep)	r   r	   messager   additional_kwargsgetr   
model_copy
model_dump)r
   r   obj_copys      r   _dump_pydantic_modelsr   +   s      	3's{{I.{{4488BBVBvy)>>t>,7=7H7H7J**84Jr   F)prettyr   kwargsc                    d|v rd}t        |      t        |       } t        |       }|r*|j                  dd      }t	        j
                  |fd|i|S t	        j
                  |fi |S )a  Return a JSON string representation of an object.

    Note:
        Plain dicts containing an `'lc'` key are automatically escaped to prevent
        confusion with LC serialization format. The escape marker is removed during
        deserialization.

    Args:
        obj: The object to dump.
        pretty: Whether to pretty print the json.

            If `True`, the json will be indented by either 2 spaces or the amount
            provided in the `indent` kwarg.
        **kwargs: Additional arguments to pass to `json.dumps`

    Returns:
        A JSON string representation of the object.

    Raises:
        ValueError: If `default` is passed as a kwarg.
    r   z'`default` should not be passed to dumpsindent   )
ValueErrorr   r   popjsondumps)r
   r   r   msg
serializedr    s         r   r%   r%   F   so    , F7o

$C!#&JHa(zz*>V>v>>::j+F++r   c                 .    t        |       } t        |       S )ay  Return a dict representation of an object.

    Note:
        Plain dicts containing an `'lc'` key are automatically escaped to prevent
        confusion with LC serialization format. The escape marker is removed during
        deserialization.

    Args:
        obj: The object to dump.

    Returns:
        Dictionary that can be serialized to json using `json.dumps`.
    )r   r   r   s    r   dumpdr)   i   s      
$CC  r   )__doc__r$   typingr   pydanticr   langchain_core.load._validationr    langchain_core.load.serializabler   r   langchain_core.messagesr   langchain_core.outputsr	   r   r   boolstrr%   r)    r   r   <module>r4      s   "    < R - 1( ( (s s 6 ',  ,s  ,t  ,s  ,s  ,F!s !s !r   