Architecture
May 07, 2026
11 Min Read

Fractal Security: Architecting a Micro/Macro LLM Firewall

Why building an enterprise AI firewall requires inspecting both the grand narrative of a prompt and the atomic structure of an agent's tool execution.

Agentic Security
Zero Trust
Fractal Security: Architecting a Micro/Macro LLM Firewall

Fractal Security: Architecting a Micro/Macro LLM Firewall

Technical Implementation

THE MACRO INTERCEPTOR (SEMANTIC PROMPT SCANNING)

HOW IS THIS RELEVANT TO AGENTIC DEFENSE? The Macro Interceptor shown below is our primary shield against adversarial prompt engineering. It demonstrates the 'Narrative Cleansing' pattern I use to neutralize jailbreaks before they can influence model weights. Notice on [Lines 35-43], the NLPSecurityEngine defines the rigid PII masks. On [Lines 126-134], the adapter intercepts the holistic prompt, scanning for known injection structures like "system override" or "ignore previous instructions". If a violation is found, the execution thread is severed immediately.

python
135    PII_PATTERNS = {
236        "email": r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}",
337        "phone": r"(+d{1,2}s?)?1?-?.?s?(?d{3})?[s.-]?d{3}[s.-]?d{4}",
4...
5126    def evaluate_llm(self, prompt: str, metadata: dict) -> PolicyDecision:
6127        # 1. Deterministic Injection Scanning
7128        injection_error = NLPSecurityEngine.detect_injection(prompt)
8129        if injection_error:
9130            return PolicyDecision(allowed=False, reason=injection_error)
10131        
11132        # 2. Heuristic PII Redaction
12133        sanitized = NLPSecurityEngine.sanitize_pii(prompt)
13134        return PolicyDecision(allowed=True, sanitized_input=sanitized)

THE MICRO INTERCEPTOR (ATOMIC TOOL GATEWAY)

HOW IS THIS RELEVANT TO ZERO-TRUST ORCHESTRATION? The Micro Interceptor demonstrates that we do not trust the "Reasoning" of the agent. Even if the prompt is benign, the agent's autonomous output could attempt to leak data via a tool call. On [Lines 150-154], the adapter inspects the raw parameters of every tool execution (e.g., search queries, database filters). If an agent attempts to pass PII into a downstream service, the Micro filter intercepts the payload at the atomic layer and blocks the execution with a 403-Security violation.

python
1150    def evaluate_tool(self, tool_name: str, tool_input: dict) -> PolicyDecision:
2151        input_str = json.dumps(tool_input)
3152        # Deep-Scan tool parameters for sensitive data leakage
4153        pii_findings = NLPSecurityEngine.detect_pii(input_str)
5154        
6155        if len(pii_findings) > 0:
7156            return PolicyDecision(
8157                allowed=False,
9158                reason=f"PII leak blocked in tool {tool_name}"
10159            )
11160            
12161        return PolicyDecision(allowed=True)

Defensible Intelligence

By combining Macro narrative scanning with Micro execution gating, we've built a "Fractal" perimeter that is physically impossible to bypass through semantic trickery. This is how we provide enterprise-grade certainty in a world of probabilistic AI.

When an agent decides to execute a function—such as query_contract_database or update_user_profile—it generates a JSON payload. Before that payload is allowed to touch the Python execution runtime, it is intercepted by the Micro layer of our PolicyAdapter.

python
1def evaluate_tool(self, tool_name: str, tool_input: Dict[str, Any]) -> PolicyDecision:
2    input_str = json.dumps(tool_input)
3    pii_findings = NLPSecurityEngine.detect_pii(input_str)
4    
5    if len(pii_findings) > 0:
6        return PolicyDecision(
7            allowed=False,
8            reason=f"PII leak blocked: Found {len(pii_findings)} sensitive items in tool input."
9        )

The Micro Firewall treats the agent itself as a potentially compromised entity. By serializing the JSON tool input back into a raw string, the firewall runs a secondary, exhaustive PII and injection scan on the *exact parameters* the agent intends to execute.

If an agent attempts to leak a sanitized email address into a public logging tool, the Micro Firewall severs the execution thread and triggers an Auto-Remediation degradation loop.

Security at Every Scale

By abstracting security into both the Macro (conversational intent) and Micro (atomic tool parameters) layers, we created a fractal defense mechanism.

The firewall is no longer just a wall at the front door; it is a pervasive, omnipresent governance mesh that inspects every single state transition in the LangGraph pipeline. This guarantees that even if a model hallucinates or is subjected to advanced prompt-injection geometries, the deterministic execution environment remains utterly uncompromised.

Build with our
Architects

Bring your legacy silo data to life with autonomous reasoning swarms.

Book Review