AI SecurityPyPI Release: llmfirewall-coreAutomated Tests: 608 passed

LLMFirewall Core — Defense-in-Depth Security Framework for AI & LLMs

Sub-millisecond in-process firewall intercepting prompt injection, PII leaks, and rogue tool execution.

Verified Milestone:608+ tests passed · Published on PyPI (llmfirewall-core) · ~0.02ms median latency
Published Python Package · PyPI Distribution
Distribution:llmfirewall-core

This project is authored and published strictly as an in-process Python library on the Python Package Index. It does not require a hosted dashboard or cloud service — executing natively within the consumer's application runtime.

View RepositoryPyPI Package
$pip install llmfirewall-core
Technologies:PythonFastAPIASGISecurity EngineeringPolicy-as-CodepytestEntropy AnalyzersAST Analysis
LLMFirewall Core
LLMFirewall Core System Interface

Problem Statement

Traditional Web Application Firewalls (WAFs) operate on HTTP payloads and know nothing about prompt semantics, indirect document poisoning, or autonomous agent tool execution parameters. Meanwhile, model-based guardrails add 500-1500ms latency and high token costs.

Engineering Goals

  • Provide in-process security with sub-millisecond overhead (<0.1ms).
  • Zero external database or cloud API dependencies.
  • Deterministic Policy-as-Code for enterprise compliance (OWASP Top 10 for LLMs, NIST AI RMF).
  • Publish as a clean, pip-installable package on PyPI.

LLMFirewall Core — System ArchitectureVerified Pipeline

Select any pipeline stage below to inspect verified engineering details and data flow.

6 Stages

Stage: Prompt / Tool Request

Role: Untrusted Input
Stack: User / Agent Invocation

Incoming natural language prompt, document payload, or proposed agent tool call.

Outbound:Injection Detector(Raw Payload)

Execution Pipeline & Mechanics

01

Token Pre-Processing & De-obfuscation

Decodes hidden Unicode homoglyphs, zero-width characters, and base64 payloads to defeat bypass attempts.

02

Adversarial Prompt Injection Detection

Matches against known injection vectors, roleplay jailbreaks, and system override constructs.

03

High-Entropy Secret Detection & PII Redaction

Calculates Shannon entropy to identify high-risk strings like AWS keys and tokens, replacing them with typed placeholders.

04

Agent Tool-Call Argument Sandboxing

Inspects proposed tool arguments to prevent SSRF against internal IP ranges and directory traversal.

05

Immutable Structured Audit Logging

Emits structured JSON audit records containing violation classifications and event fingerprints.

Engineering Challenges & Design Decisions

Decision: In-process deterministic rules over secondary LLM judge

Rationale: Secondary LLM judges introduce 400-1000ms latency and their own susceptibility to adversarial persuasion. In-process deterministic checks execute in 0.02ms with zero token cost.

Alternative Rejected: Llama-Guard / OpenAI Moderation API roundtrips.

Core Architectural Highlights

LLMFirewall operates as an ASGI middleware or Python function decorator. Payloads pass through a multi-stage validation chain before dispatch to the downstream LLM or agent runtime. If an anomaly or unauthorized action is detected, it fails closed with structured error objects.

•Published llmfirewall-core to the official Python Package Index (PyPI).
•Engineered an ultra-fast compiled regex and entropy scanning engine measuring ~0.02ms median latency.
•Created an ASGI middleware drop-in for FastAPI that intercepts payloads at the network boundary.
•Implemented 608 automated tests with comprehensive attack payload suites.

Testing & Empirical Evaluation

608 automated test cases covering adversarial prompt injection datasets, credential leakage patterns, tool argument tampering, and concurrency stress tests.

Result #1
608 passing unit and integration tests
Result #2
Sub-millisecond overhead: ~0.02 ms median execution latency
Result #3
Zero false positives across standard benign prompt baseline corpus

Security & Reliability Defenses

Fail-closed architecture: Any unhandled exception during security evaluation causes the request to be rejected safely.
No network egress required, preventing side-channel data exfiltration.

Key Engineering Learnings

  • •Adversaries frequently use zero-width Unicode characters to evade naive string matching; canonicalization must precede all heuristic scans.

Local Reproduction & Setup Commands

$pip install llmfirewall-core
$from llmfirewall import Firewall
$fw = Firewall(policy='strict')
$result = fw.inspect('User prompt here')