Home / File/ _redaction.py — langchain Source File

_redaction.py — langchain Source File

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

File python CoreAbstractions MessageSchema 9 imports 11 functions 4 classes

Entity Profile

Dependency Diagram

graph LR
  9a4d80ea_ca2c_826e_7f10_00b652b898cc["_redaction.py"]
  ca3eea8c_ddf5_4ba7_a40c_5ed2287c91fa["hashlib"]
  9a4d80ea_ca2c_826e_7f10_00b652b898cc --> ca3eea8c_ddf5_4ba7_a40c_5ed2287c91fa
  62873f8b_8a94_85c2_95cc_97f5dd78db74["ipaddress"]
  9a4d80ea_ca2c_826e_7f10_00b652b898cc --> 62873f8b_8a94_85c2_95cc_97f5dd78db74
  7aaf52d4_ee88_411e_980e_bc4beeeb30ad["operator"]
  9a4d80ea_ca2c_826e_7f10_00b652b898cc --> 7aaf52d4_ee88_411e_980e_bc4beeeb30ad
  67ec3255_645e_8b6e_1eff_1eb3c648ed95["re"]
  9a4d80ea_ca2c_826e_7f10_00b652b898cc --> 67ec3255_645e_8b6e_1eff_1eb3c648ed95
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  9a4d80ea_ca2c_826e_7f10_00b652b898cc --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  aac5f8ad_7f2a_3a8e_3b4b_b07d681cbdcf["dataclasses"]
  9a4d80ea_ca2c_826e_7f10_00b652b898cc --> aac5f8ad_7f2a_3a8e_3b4b_b07d681cbdcf
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  9a4d80ea_ca2c_826e_7f10_00b652b898cc --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  c89186be_3766_27dd_efaa_6092bf0ccc74["urllib.parse"]
  9a4d80ea_ca2c_826e_7f10_00b652b898cc --> c89186be_3766_27dd_efaa_6092bf0ccc74
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  9a4d80ea_ca2c_826e_7f10_00b652b898cc --> 91721f45_4909_e489_8c1f_084f8bd87145
  style 9a4d80ea_ca2c_826e_7f10_00b652b898cc fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Shared redaction utilities for middleware components."""

from __future__ import annotations

import hashlib
import ipaddress
import operator
import re
from collections.abc import Callable, Sequence
from dataclasses import dataclass
from typing import Literal
from urllib.parse import urlparse

from typing_extensions import TypedDict

RedactionStrategy = Literal["block", "redact", "mask", "hash"]
"""Supported strategies for handling detected sensitive values."""


class PIIMatch(TypedDict):
    """Represents an individual match of sensitive data."""

    type: str
    value: str
    start: int
    end: int


class PIIDetectionError(Exception):
    """Raised when configured to block on detected sensitive values."""

    def __init__(self, pii_type: str, matches: Sequence[PIIMatch]) -> None:
        """Initialize the exception with match context.

        Args:
            pii_type: Name of the detected sensitive type.
            matches: All matches that were detected for that type.
        """
        self.pii_type = pii_type
        self.matches = list(matches)
        count = len(matches)
        msg = f"Detected {count} instance(s) of {pii_type} in text content"
        super().__init__(msg)


Detector = Callable[[str], list[PIIMatch]]
"""Callable signature for detectors that locate sensitive values."""


def detect_email(content: str) -> list[PIIMatch]:
    """Detect email addresses in content.

    Args:
        content: The text content to scan for email addresses.

    Returns:
        A list of detected email matches.
    """
    pattern = r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b"
    return [
// ... (377 more lines)

Subdomains

Dependencies

  • collections.abc
  • dataclasses
  • hashlib
  • ipaddress
  • operator
  • re
  • typing
  • typing_extensions
  • urllib.parse

Frequently Asked Questions

What does _redaction.py do?
_redaction.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in _redaction.py?
_redaction.py defines 11 function(s): _apply_hash_strategy, _apply_mask_strategy, _apply_redact_strategy, _passes_luhn, apply_strategy, detect_credit_card, detect_email, detect_ip, detect_mac_address, detect_url, and 1 more.
What does _redaction.py depend on?
_redaction.py imports 9 module(s): collections.abc, dataclasses, hashlib, ipaddress, operator, re, typing, typing_extensions, and 1 more.
Where is _redaction.py in the architecture?
_redaction.py is located at libs/langchain_v1/langchain/agents/middleware/_redaction.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/langchain_v1/langchain/agents/middleware).

Analyze Your Own Codebase

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

Try Supermodel Free