Home / File/ test_schema.py — langchain Source File

test_schema.py — langchain Source File

Architecture documentation for test_schema.py, a python file in the langchain codebase. 7 imports, 0 dependents.

File python LangChainCore ApiManagement 7 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  4c6c4c75_8d7c_8b16_aaff_caa28457a9a9["test_schema.py"]
  f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"]
  4c6c4c75_8d7c_8b16_aaff_caa28457a9a9 --> f69d6389_263d_68a4_7fbf_f14c0602a9ba
  59e0d3b0_0f8e_4b79_d442_e9b4821561c7["langchain_core.agents"]
  4c6c4c75_8d7c_8b16_aaff_caa28457a9a9 --> 59e0d3b0_0f8e_4b79_d442_e9b4821561c7
  6a98b0a5_5607_0043_2e22_a46a464c2d62["langchain_core.documents"]
  4c6c4c75_8d7c_8b16_aaff_caa28457a9a9 --> 6a98b0a5_5607_0043_2e22_a46a464c2d62
  9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"]
  4c6c4c75_8d7c_8b16_aaff_caa28457a9a9 --> 9444498b_8066_55c7_b3a2_1d90c4162a32
  4382dc25_6fba_324a_49e2_e9742d579385["langchain_core.outputs"]
  4c6c4c75_8d7c_8b16_aaff_caa28457a9a9 --> 4382dc25_6fba_324a_49e2_e9742d579385
  b9f9a99f_aaea_6efd_1322_fc2c11bdc4b4["langchain_core.prompt_values"]
  4c6c4c75_8d7c_8b16_aaff_caa28457a9a9 --> b9f9a99f_aaea_6efd_1322_fc2c11bdc4b4
  dd5e7909_a646_84f1_497b_cae69735550e["pydantic"]
  4c6c4c75_8d7c_8b16_aaff_caa28457a9a9 --> dd5e7909_a646_84f1_497b_cae69735550e
  style 4c6c4c75_8d7c_8b16_aaff_caa28457a9a9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Test formatting functionality."""

import pytest
from langchain_core.agents import AgentAction, AgentActionMessageLog, AgentFinish
from langchain_core.documents import Document
from langchain_core.messages import (
    AIMessage,
    AIMessageChunk,
    ChatMessage,
    ChatMessageChunk,
    FunctionMessage,
    FunctionMessageChunk,
    HumanMessage,
    HumanMessageChunk,
    SystemMessage,
    SystemMessageChunk,
    ToolMessage,
)
from langchain_core.outputs import ChatGeneration, ChatGenerationChunk, Generation
from langchain_core.prompt_values import ChatPromptValueConcrete, StringPromptValue
from pydantic import RootModel, ValidationError


@pytest.mark.xfail(reason="TODO: FIX BEFORE 0.3 RELEASE")
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)}"

    with pytest.raises((TypeError, ValidationError)):
        # Make sure that specifically validation error is raised
        well_known_lc_object.model_validate({})

Domain

Subdomains

Dependencies

  • langchain_core.agents
  • langchain_core.documents
  • langchain_core.messages
  • langchain_core.outputs
  • langchain_core.prompt_values
  • pydantic
  • pytest

Frequently Asked Questions

What does test_schema.py do?
test_schema.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, ApiManagement subdomain.
What functions are defined in test_schema.py?
test_schema.py defines 1 function(s): test_serialization_of_wellknown_objects.
What does test_schema.py depend on?
test_schema.py imports 7 module(s): langchain_core.agents, langchain_core.documents, langchain_core.messages, langchain_core.outputs, langchain_core.prompt_values, pydantic, pytest.
Where is test_schema.py in the architecture?
test_schema.py is located at libs/langchain/tests/unit_tests/test_schema.py (domain: LangChainCore, subdomain: ApiManagement, directory: libs/langchain/tests/unit_tests).

Analyze Your Own Codebase

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

Try Supermodel Free