Home / Function/ test_serialization_of_wellknown_objects() — langchain Function Reference

test_serialization_of_wellknown_objects() — langchain Function Reference

Architecture documentation for the test_serialization_of_wellknown_objects() function in test_schema.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  e9dae0e3_8999_b425_1a6b_975a465c24c2["test_serialization_of_wellknown_objects()"]
  4c6c4c75_8d7c_8b16_aaff_caa28457a9a9["test_schema.py"]
  e9dae0e3_8999_b425_1a6b_975a465c24c2 -->|defined in| 4c6c4c75_8d7c_8b16_aaff_caa28457a9a9
  style e9dae0e3_8999_b425_1a6b_975a465c24c2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/tests/unit_tests/test_schema.py lines 25–108

def test_serialization_of_wellknown_objects() -> None:
    """Test that pydantic is able to serialize and deserialize well known objects."""
    well_known_lc_object = RootModel[
        Document
        | HumanMessage
        | SystemMessage
        | ChatMessage
        | FunctionMessage
        | FunctionMessageChunk
        | AIMessage
        | HumanMessageChunk
        | SystemMessageChunk
        | ChatMessageChunk
        | AIMessageChunk
        | StringPromptValue
        | ChatPromptValueConcrete
        | AgentFinish
        | AgentAction
        | AgentActionMessageLog
        | ChatGeneration
        | Generation
        | ChatGenerationChunk,
    ]

    lc_objects = [
        HumanMessage(content="human"),
        HumanMessageChunk(content="human"),
        AIMessage(content="ai"),
        AIMessageChunk(content="ai"),
        SystemMessage(content="sys"),
        SystemMessageChunk(content="sys"),
        FunctionMessage(
            name="func",
            content="func",
        ),
        FunctionMessageChunk(
            name="func",
            content="func",
        ),
        ChatMessage(
            role="human",
            content="human",
        ),
        ChatMessageChunk(
            role="human",
            content="human",
        ),
        StringPromptValue(text="hello"),
        ChatPromptValueConcrete(messages=[AIMessage(content="foo")]),
        ChatPromptValueConcrete(messages=[HumanMessage(content="human")]),
        ChatPromptValueConcrete(
            messages=[ToolMessage(content="foo", tool_call_id="bar")],
        ),
        ChatPromptValueConcrete(messages=[SystemMessage(content="foo")]),
        Document(page_content="hello"),
        AgentFinish(return_values={}, log=""),
        AgentAction(tool="tool", tool_input="input", log=""),
        AgentActionMessageLog(
            tool="tool",
            tool_input="input",
            log="",
            message_log=[HumanMessage(content="human")],
        ),
        Generation(
            text="hello",
            generation_info={"info": "info"},
        ),
        ChatGeneration(
            message=HumanMessage(content="human"),
        ),
        ChatGenerationChunk(
            message=HumanMessageChunk(content="cat"),
        ),
    ]

    for lc_object in lc_objects:
        d = lc_object.model_dump()
        assert "type" in d, f"Missing key `type` for {type(lc_object)}"
        obj1 = well_known_lc_object.model_validate(d)
        assert type(obj1.root) is type(lc_object), f"failed for {type(lc_object)}"

Domain

Subdomains

Frequently Asked Questions

What does test_serialization_of_wellknown_objects() do?
test_serialization_of_wellknown_objects() is a function in the langchain codebase, defined in libs/langchain/tests/unit_tests/test_schema.py.
Where is test_serialization_of_wellknown_objects() defined?
test_serialization_of_wellknown_objects() is defined in libs/langchain/tests/unit_tests/test_schema.py at line 25.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free