๐ง AI Model Privacy LeaksJuly 8, 2026โ
Tests passing
AI Output Sanitizer
This tool scans AI-generated text outputs for sensitive data patterns, such as API keys, secrets, or private URLs, and replaces or flags them. It helps developers ensure that AI outputs don't inadvertently expose private information.
What It Does
- Scans text for sensitive data patterns using customizable rules.
- Flags or masks sensitive data based on user preference.
- Supports JSON-based rule definitions for flexibility.
Installation
1. Clone the repository or download the script.
2. Install the required Python package:
pip install coloramaUsage
Run the script from the command line:
python ai_output_sanitizer.py --input <input_file> --rules <rules_file> [--mask]Arguments
--input: Path to the input text file to be scanned.--rules: Path to the JSON file containing detection rules.--mask: Optional flag to mask sensitive data instead of just flagging it.
Example
python ai_output_sanitizer.py --input sample.txt --rules rules.json --maskSource Code
import argparse
import re
import json
import sys
from colorama import Fore, Style
def load_rules(rules_path):
"""Load detection rules from a JSON file."""
try:
with open(rules_path, 'r') as f:
return json.load(f)
except FileNotFoundError:
print(f"{Fore.RED}Error: Rules file not found: {rules_path}{Style.RESET_ALL}")
sys.exit(1)
except json.JSONDecodeError:
print(f"{Fore.RED}Error: Invalid JSON in rules file: {rules_path}{Style.RESET_ALL}")
sys.exit(1)
def sanitize_text(text, rules, mask):
"""Scan and sanitize text based on rules."""
sanitized_text = text
flagged_items = []
for rule in rules:
pattern = rule.get("pattern")
description = rule.get("description", "Sensitive data")
if not pattern:
continue
matches = re.findall(pattern, text)
for match in matches:
flagged_items.append((match, description))
if mask:
sanitized_text = re.sub(re.escape(match), "[REDACTED]", sanitized_text)
return sanitized_text, flagged_items
def main():
parser = argparse.ArgumentParser(description="AI Output Sanitizer")
parser.add_argument("--input", help="Path to the input text file", required=True)
parser.add_argument("--rules", help="Path to the JSON rules file", required=True)
parser.add_argument("--mask", help="Mask sensitive data instead of just flagging", action="store_true")
args = parser.parse_args()
try:
with open(args.input, 'r') as f:
input_text = f.read()
except FileNotFoundError:
print(f"{Fore.RED}Error: Input file not found: {args.input}{Style.RESET_ALL}")
sys.exit(1)
rules = load_rules(args.rules)
sanitized_text, flagged_items = sanitize_text(input_text, rules, args.mask)
if flagged_items:
print(f"{Fore.YELLOW}Flagged sensitive data:{Style.RESET_ALL}")
for item, description in flagged_items:
print(f"- {description}: {item}")
print(f"{Fore.GREEN}Sanitized Output:{Style.RESET_ALL}\n")
print(sanitized_text)
if __name__ == "__main__":
main()
Community
Downloads
ยทยทยท
Rate this tool
No ratings yet โ be the first!
Details
- Tool Name
- ai_output_sanitizer
- Category
- AI Model Privacy Leaks
- Generated
- July 8, 2026
- Tests
- Passing โ
- Fix Loops
- 2
Quick Install
Clone just this tool:
git clone --depth 1 --filter=blob:none --sparse \ https://github.com/ptulin/autoaiforge.git cd autoaiforge git sparse-checkout set generated_tools/2026-07-08/ai_output_sanitizer cd generated_tools/2026-07-08/ai_output_sanitizer pip install -r requirements.txt 2>/dev/null || true python ai_output_sanitizer.py