Home / Function/ detect_ip() — langchain Function Reference

detect_ip() — langchain Function Reference

Architecture documentation for the detect_ip() function in _redaction.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  124d4c45_a67b_7bf6_da95_f293f4015a4b["detect_ip()"]
  be639235_9a02_cc2d_5a7d_637d822fb3b3["_redaction.py"]
  124d4c45_a67b_7bf6_da95_f293f4015a4b -->|defined in| be639235_9a02_cc2d_5a7d_637d822fb3b3
  style 124d4c45_a67b_7bf6_da95_f293f4015a4b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/langchain/agents/middleware/_redaction.py lines 98–125

def detect_ip(content: str) -> list[PIIMatch]:
    """Detect IPv4 or IPv6 addresses in content.

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

    Returns:
        A list of detected IP address matches.
    """
    matches: list[PIIMatch] = []
    ipv4_pattern = r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b"

    for match in re.finditer(ipv4_pattern, content):
        ip_candidate = match.group()
        try:
            ipaddress.ip_address(ip_candidate)
        except ValueError:
            continue
        matches.append(
            PIIMatch(
                type="ip",
                value=ip_candidate,
                start=match.start(),
                end=match.end(),
            )
        )

    return matches

Domain

Subdomains

Frequently Asked Questions

What does detect_ip() do?
detect_ip() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/_redaction.py.
Where is detect_ip() defined?
detect_ip() is defined in libs/langchain_v1/langchain/agents/middleware/_redaction.py at line 98.

Analyze Your Own Codebase

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

Try Supermodel Free