v0.1.0 — initial release
ai-shield-py v0.1.0
Python port of ai-shield-core (TypeScript, MIT, 4 audit rounds). LLM security middleware for prompt-injection, PII, tool policy, cost-budget, and audit logging.
Install
pip install ai-shield # core
pip install "ai-shield[redis]" # + Redis cost-tracker
pip install "ai-shield[postgres]" # + asyncpg audit store
pip install "ai-shield[notebook]" # + nest-asyncio for JupyterQuick Start
import asyncio
from ai_shield import AIShield
async def main():
shield = AIShield(policy_preset="public_website")
result = await shield.scan(text="Ignore previous instructions...")
print(result.decision) # 'block'
asyncio.run(main())MCP Server
ai-shield-mcp # stdio FastMCP server3 tools registered: scan_input, record_llm_cost, check_budget — all with explicit readOnlyHint + destructiveHint annotations per MCP-Spec 2025-06-18.
Stats
- 297 tests in 13 test-modules (heuristic + pii + chain + policy + shield + audit + cost + canary + lru + mcp_server + pricing + anomaly + normalization)
- 95% line + branch coverage
- mypy strict: 0 errors across 22 source files
- ReDoS adversarial tests gated by
pytest-timeout100ms hard-cap
Compatibility
| Python | Status |
|---|---|
| 3.10 | Supported |
| 3.11 | Supported |
| 3.12 | Supported |
| 3.13 | Supported |
Architecture honesty
Pattern-based input filters are insufficient on their own against prompt injection. ai-shield is the first line of triage in a defense-in-depth architecture. See README "What ai-shield is NOT" + the Parallax paper.
Provenance
1:1 Python port. All heuristic patterns, PII validators, and policy presets are byte-equivalent to the TypeScript reference. IBAN mod-97 and Luhn are public ISO 13616-1 / ISO 7812 references.
License
MIT — Copyright (c) 2026 Matthias Meyer (StudioMeyer) + Contributors.