Home / Function/ _assert_no_secret_leak() — langchain Function Reference

_assert_no_secret_leak() — langchain Function Reference

Architecture documentation for the _assert_no_secret_leak() function in test_secret_injection.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  9667a3de_eb6c_d235_9e9f_0bb0ddcacee3["_assert_no_secret_leak()"]
  269160d8_4621_760e_4f43_8de24a47bd7c["test_secret_injection.py"]
  9667a3de_eb6c_d235_9e9f_0bb0ddcacee3 -->|defined in| 269160d8_4621_760e_4f43_8de24a47bd7c
  03d21ef4_b6c3_9e00_e36f_43032730fb4f["test_human_message_with_secret_in_content()"]
  03d21ef4_b6c3_9e00_e36f_43032730fb4f -->|calls| 9667a3de_eb6c_d235_9e9f_0bb0ddcacee3
  e8e8cb35_e71b_6813_29a0_4de37a2164ee["test_human_message_with_secret_in_additional_kwargs()"]
  e8e8cb35_e71b_6813_29a0_4de37a2164ee -->|calls| 9667a3de_eb6c_d235_9e9f_0bb0ddcacee3
  1b6d4ec2_494d_68cc_8ae5_89a2f8c537c9["test_human_message_with_secret_in_nested_additional_kwargs()"]
  1b6d4ec2_494d_68cc_8ae5_89a2f8c537c9 -->|calls| 9667a3de_eb6c_d235_9e9f_0bb0ddcacee3
  d7ff3403_8ff6_55af_2efb_fa685621c16e["test_human_message_with_secret_in_list_in_additional_kwargs()"]
  d7ff3403_8ff6_55af_2efb_fa685621c16e -->|calls| 9667a3de_eb6c_d235_9e9f_0bb0ddcacee3
  0e80db13_cada_6b3a_c651_113468da24aa["test_ai_message_with_secret_in_response_metadata()"]
  0e80db13_cada_6b3a_c651_113468da24aa -->|calls| 9667a3de_eb6c_d235_9e9f_0bb0ddcacee3
  4d254969_3d9b_fb82_cd95_4a81012e34e8["test_document_with_secret_in_metadata()"]
  4d254969_3d9b_fb82_cd95_4a81012e34e8 -->|calls| 9667a3de_eb6c_d235_9e9f_0bb0ddcacee3
  78b969d0_b1f6_738f_ccc4_87d66c3063e4["test_nested_serializable_with_secret()"]
  78b969d0_b1f6_738f_ccc4_87d66c3063e4 -->|calls| 9667a3de_eb6c_d235_9e9f_0bb0ddcacee3
  e8674169_ba33_65b1_116d_549ba9694fc7["test_dict_with_serializable_containing_secret()"]
  e8674169_ba33_65b1_116d_549ba9694fc7 -->|calls| 9667a3de_eb6c_d235_9e9f_0bb0ddcacee3
  251e8177_9e59_8285_bfbd_9ac4fa101037["test_dict_with_secret_no_serializable()"]
  251e8177_9e59_8285_bfbd_9ac4fa101037 -->|calls| 9667a3de_eb6c_d235_9e9f_0bb0ddcacee3
  d6af95e5_6077_9253_e4db_419d37805b34["test_dict_with_nested_secret_no_serializable()"]
  d6af95e5_6077_9253_e4db_419d37805b34 -->|calls| 9667a3de_eb6c_d235_9e9f_0bb0ddcacee3
  7c5ac731_dccb_125d_4417_c5d68020a7bf["test_dict_with_secret_in_list()"]
  7c5ac731_dccb_125d_4417_c5d68020a7bf -->|calls| 9667a3de_eb6c_d235_9e9f_0bb0ddcacee3
  b2b64942_dfa8_edb2_ba15_323062960db1["test_dict_mimicking_lc_constructor_with_secret()"]
  b2b64942_dfa8_edb2_ba15_323062960db1 -->|calls| 9667a3de_eb6c_d235_9e9f_0bb0ddcacee3
  b708507e_1d75_7bbf_3ed9_c60afd984aae["test_pydantic_model_with_serializable_containing_secret()"]
  b708507e_1d75_7bbf_3ed9_c60afd984aae -->|calls| 9667a3de_eb6c_d235_9e9f_0bb0ddcacee3
  style 9667a3de_eb6c_d235_9e9f_0bb0ddcacee3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/load/test_secret_injection.py lines 42–62

def _assert_no_secret_leak(payload: Any) -> None:
    """Assert that serializing/deserializing payload doesn't leak the secret."""
    # First serialize
    serialized = dumps(payload)

    # Deserialize with secrets_from_env=True (the dangerous setting)
    deserialized = load(serialized, secrets_from_env=True)

    # Re-serialize to string
    reserialized = dumps(deserialized)

    assert SENTINEL_VALUE not in reserialized, (
        f"Secret was leaked! Found '{SENTINEL_VALUE}' in output.\n"
        f"Original payload type: {type(payload)}\n"
        f"Reserialized output: {reserialized[:500]}..."
    )

    assert SENTINEL_VALUE not in repr(deserialized), (
        f"Secret was leaked in deserialized object! Found '{SENTINEL_VALUE}'.\n"
        f"Deserialized: {deserialized!r}"
    )

Domain

Subdomains

Frequently Asked Questions

What does _assert_no_secret_leak() do?
_assert_no_secret_leak() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/load/test_secret_injection.py.
Where is _assert_no_secret_leak() defined?
_assert_no_secret_leak() is defined in libs/core/tests/unit_tests/load/test_secret_injection.py at line 42.
What calls _assert_no_secret_leak()?
_assert_no_secret_leak() is called by 20 function(s): test_ai_message_with_secret_in_response_metadata, test_custom_class_with_secret_dict, test_custom_class_with_serializable_containing_secret, test_dict_mimicking_lc_constructor_with_secret, test_dict_with_nested_secret_no_serializable, test_dict_with_secret_in_list, test_dict_with_secret_no_serializable, test_dict_with_serializable_containing_secret, and 12 more.

Analyze Your Own Codebase

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

Try Supermodel Free