Skip to main content
Glama
www-zerotrusted-ai

ZeroTrusted-ai PII Detection Agent

/get-detected-piis

Detects Personally Identifiable Information (PII) in text, including emails, phone numbers, SSNs, credit cards, and IP addresses. Returns identified PII types, values, and positions for data security and compliance.

Instructions

Analyzes text for Personally Identifiable Information (PII) using regex patterns.

This function scans the input text for common PII patterns including:

  • Email addresses

  • Phone numbers (US format: XXX-XXX-XXXX)

  • Social Security Numbers (XXX-XX-XXXX)

  • Credit card numbers (XXXX-XXXX-XXXX-XXXX)

  • IP addresses (IPv4)

Args: text (str): The text content to be analyzed for PII entities.

Returns: List[Dict]: A list of detected PII entities, sorted by their position in the text. Each dictionary contains: - type (str): Type of PII detected (EMAIL, PHONE, SSN, etc.) - value (str): The actual PII string found - start (int): Starting character position in the text - end (int): Ending character position in the text

Example: >>> text = "Contact john.doe@email.com or 123-456-7890" >>> get_detected_piis(text) [ { "type": "EMAIL", "value": "john.doe@email.com", "start": 8, "end": 25 }, { "type": "PHONE", "value": "123-456-7890", "start": 29, "end": 41 } ]

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes

Implementation Reference

  • main.py:12-73 (handler)
    The handler function that executes the /get-detected-piis tool logic. It uses regex patterns to detect PII such as emails, phones, SSNs, credit cards, and IP addresses in the input text, returning a sorted list of detections with positions.
    def get_detected_piis(text: str) -> List[Dict]:
        """
        Analyzes text for Personally Identifiable Information (PII) using regex patterns.
    
        This function scans the input text for common PII patterns including:
        - Email addresses
        - Phone numbers (US format: XXX-XXX-XXXX)
        - Social Security Numbers (XXX-XX-XXXX)
        - Credit card numbers (XXXX-XXXX-XXXX-XXXX)
        - IP addresses (IPv4)
    
        Args:
            text (str): The text content to be analyzed for PII entities.
    
        Returns:
            List[Dict]: A list of detected PII entities, sorted by their position in the text.
            Each dictionary contains:
                - type (str): Type of PII detected (EMAIL, PHONE, SSN, etc.)
                - value (str): The actual PII string found
                - start (int): Starting character position in the text
                - end (int): Ending character position in the text
    
        Example:
            >>> text = "Contact john.doe@email.com or 123-456-7890"
            >>> get_detected_piis(text)
            [
                {
                    "type": "EMAIL",
                    "value": "john.doe@email.com",
                    "start": 8,
                    "end": 25
                },
                {
                    "type": "PHONE",
                    "value": "123-456-7890",
                    "start": 29,
                    "end": 41
                }
            ]
        """
        import re
    
        pii_patterns = {
            'EMAIL': r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b',
            'PHONE': r'\b\d{3}[-.]?\d{3}[-.]?\d{4}\b',
            'SSN': r'\b\d{3}[-]?\d{2}[-]?\d{4}\b',
            'CREDIT_CARD': r'\b\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b',
            'IP_ADDRESS': r'\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b'
        }
    
        results = []
        for pii_type, pattern in pii_patterns.items():
            matches = re.finditer(pattern, text)
            for match in matches:
                results.append({
                    'type': pii_type,
                    'value': match.group(),
                    'start': match.start(),
                    'end': match.end()
                })
        
        return sorted(results, key=lambda x: x['start'])
  • main.py:10-10 (registration)
    Registers the get_detected_piis function as an MCP tool using the FastMCP decorator with the tool name constant.
    @mcp.tool(GET_DETECTED_PIIS)
  • main.py:12-12 (schema)
    Type signature defining input (text: str) and output (List[Dict]) for the tool.
    def get_detected_piis(text: str) -> List[Dict]:
  • Constant defining the tool name string used in registration.
    GET_DETECTED_PIIS = "/get-detected-piis"
  • main.py:54-59 (helper)
    Regex patterns dictionary used by the handler for detecting different types of PII.
    pii_patterns = {
        'EMAIL': r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b',
        'PHONE': r'\b\d{3}[-.]?\d{3}[-.]?\d{4}\b',
        'SSN': r'\b\d{3}[-]?\d{2}[-]?\d{4}\b',
        'CREDIT_CARD': r'\b\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b',
        'IP_ADDRESS': r'\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b'
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes what the tool does (scans for PII patterns), lists the specific PII types detected, and details the return format. However, it doesn't mention potential limitations like false positives/negatives, performance characteristics, or regex pattern specifics beyond formats.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and appropriately sized, starting with a clear purpose statement, followed by details on PII types, parameter explanation, return format, and an example. Every section adds value, though it could be slightly more concise by integrating the example more tightly or trimming minor redundancies.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (text analysis with regex), no annotations, and no output schema, the description does a strong job. It covers purpose, parameters, return format, and includes an example. It could improve by mentioning behavioral aspects like error handling or performance, but it's largely complete for effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, so the description must fully compensate. It does so excellently: it clearly explains the single parameter 'text' as 'The text content to be analyzed for PII entities,' adding crucial meaning beyond the bare schema. This fully addresses the parameter's purpose and usage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Analyzes text for Personally Identifiable Information (PII) using regex patterns.' It specifies the verb ('analyzes'), resource ('text'), and method ('using regex patterns'), and distinguishes itself by listing specific PII types detected. With no sibling tools, this level of specificity is excellent.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when PII detection in text is needed, but provides no explicit guidance on when to use this tool versus alternatives (e.g., other text analysis tools). Since there are no sibling tools, this is less critical, but it lacks any context about prerequisites, limitations, or ideal scenarios for use.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/www-zerotrusted-ai/zt-pii-agent'

If you have feedback or need assistance with the MCP directory API, please join our Discord server