Public
PythonSecurityLLMPrompt InjectionToken OptimizationNLP

Content Sanitizer & TOON Normalizer

A Python library that strips hostile surface area from untrusted HTML and text, then compacts what remains to a semantic core — cutting token load on typical web content by roughly 95% while preserving structured artifacts like IOCs.

View Source ↗

The Problem

Feeding the web straight into an LLM imports invisible Unicode, nested markup, and instruction smuggling. Naive stripping deletes semantics; naive summarization destroys IOC fidelity. The sanitizer and TOON stages split those concerns so security and token economics do not fight each other.

Approach

The sanitizer walks DOM-like structures with an explicit allowlist, removes scriptable surfaces, normalizes homoglyphs, and collapses steganographic carriers encountered in experimentation. TOON then rewrites cleaned text into a compact canonical representation tuned for downstream models — aggressive on fluff, conservative on tables, lists, and security-relevant strings.

Architecture

Raw HTML / text
  → sanitizer (structure + unicode + injection patterns)
    → TOON normalizer (semantic compaction)
      → LiteLLM / agents (bounded context)

Key Design Decisions

Direction

More adversarial fixtures from live CTI pulls, tighter coupling with gateway metrics, and optional language-specific compaction profiles for logs versus prose.

← All Development