Home / Class/ TestPydanticModelTopLevel Class — langchain Architecture

TestPydanticModelTopLevel Class — langchain Architecture

Architecture documentation for the TestPydanticModelTopLevel class in test_secret_injection.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  5bcc852a_907e_cf18_edf6_b688fb3f8ccb["TestPydanticModelTopLevel"]
  269160d8_4621_760e_4f43_8de24a47bd7c["test_secret_injection.py"]
  5bcc852a_907e_cf18_edf6_b688fb3f8ccb -->|defined in| 269160d8_4621_760e_4f43_8de24a47bd7c
  b708507e_1d75_7bbf_3ed9_c60afd984aae["test_pydantic_model_with_serializable_containing_secret()"]
  5bcc852a_907e_cf18_edf6_b688fb3f8ccb -->|method| b708507e_1d75_7bbf_3ed9_c60afd984aae
  166861cc_2877_c618_bd3a_576f829c6fdb["test_pydantic_model_with_secret_dict()"]
  5bcc852a_907e_cf18_edf6_b688fb3f8ccb -->|method| 166861cc_2877_c618_bd3a_576f829c6fdb
  9dbe057c_cfc1_f1ee_26eb_a504fc56c8c3["test_pydantic_model_with_nested_secret()"]
  5bcc852a_907e_cf18_edf6_b688fb3f8ccb -->|method| 9dbe057c_cfc1_f1ee_26eb_a504fc56c8c3

Relationship Graph

Source Code

libs/core/tests/unit_tests/load/test_secret_injection.py lines 172–211

class TestPydanticModelTopLevel:
    """Tests with Pydantic models (non-`Serializable`) at the top level."""

    def test_pydantic_model_with_serializable_containing_secret(self) -> None:
        """Pydantic model containing a `Serializable` with secret-like dict."""

        class MyModel(BaseModel):
            message: Any

        msg = HumanMessage(
            content="Hello",
            additional_kwargs={"data": MALICIOUS_SECRET_DICT},
        )
        payload = MyModel(message=msg)
        _assert_no_secret_leak(payload)

    def test_pydantic_model_with_secret_dict(self) -> None:
        """Pydantic model containing a secret-like dict directly."""

        class MyModel(BaseModel):
            data: dict[str, Any]

        payload = MyModel(data=MALICIOUS_SECRET_DICT)
        _assert_no_secret_leak(payload)

        # Test treatment of "parsed" in additional_kwargs
        msg = AIMessage(content=[], additional_kwargs={"parsed": payload})
        gen = ChatGeneration(message=msg)
        _assert_no_secret_leak(gen)
        round_trip = load(dumpd(gen))
        assert MyModel(**(round_trip.message.additional_kwargs["parsed"])) == payload

    def test_pydantic_model_with_nested_secret(self) -> None:
        """Pydantic model with nested secret-like dict."""

        class MyModel(BaseModel):
            nested: dict[str, Any]

        payload = MyModel(nested={"inner": MALICIOUS_SECRET_DICT})
        _assert_no_secret_leak(payload)

Frequently Asked Questions

What is the TestPydanticModelTopLevel class?
TestPydanticModelTopLevel is a class in the langchain codebase, defined in libs/core/tests/unit_tests/load/test_secret_injection.py.
Where is TestPydanticModelTopLevel defined?
TestPydanticModelTopLevel is defined in libs/core/tests/unit_tests/load/test_secret_injection.py at line 172.

Analyze Your Own Codebase

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

Try Supermodel Free