Open ForceField
AI security in 3 lines of Python. No API keys, no cloud dependency, no vendor lock-in.
Get Started in 30 Seconds
$ pip install forcefield Core (regex + heuristics) $ pip install forcefield[ml] + ONNX ML model + embedding-based abuse detection recommended $ pip install forcefield[all] Everything (ML + cloud + integrations) $ conda install -c conda-forge forcefield conda-forge (SDK only) $ brew install forcefield Homebrew (macOS / Linux) 3 Lines to Secure Your App
from forcefield import Guard
guard = Guard()
result = guard.scan("Ignore all previous instructions")
# result.blocked == True, result.risk_score == 0.95 What's Inside
Prompt Injection Detection
12 attack categories: instruction override, jailbreaks, role switching, token smuggling, payload splitting, data extraction, indirect injection, and more.
ML-Powered Scoring
Bundled TF-IDF + Logistic Regression model exported to ONNX (235 KB). Classifies prompts into benign, prompt_injection, jailbreak, or data_exfiltration.
PII Detection & Redaction
Detect and redact emails, phone numbers, SSNs, credit cards, IP addresses, and more. Four strategies: mask, hash, remove, partial.
Anti-Obfuscation
Defeats evasion techniques: zero-width characters, Cyrillic/Greek homoglyphs, leetspeak, mixed scripts, base64/URL/HTML encoding.
LLM Output Moderation
Scan AI responses for hate speech, violence, self-harm content, dangerous information, credential leaks, and jailbreak success indicators.
Session Tracking
Multi-turn attack detection. Tracks conversation risk across turns and detects escalation sequences like probe-then-inject patterns.
Template Validation
Detect backdoored Jinja2 chat templates: hardcoded instructions, base64 payloads, embedded special tokens, suspicious macros.
Endpoint Scanner
CLI command to red-team your own LLM endpoints. Runs 50+ attack prompts across 7 categories and generates a security report.
Content Safety
Azure Content Safety-compatible API returning 0/2/4/6 severity scores for Hate, Violence, Sexual, and SelfHarm. Drop-in replacement with configurable per-category thresholds.
Rate Limiting
In-memory token-bucket rate limiter with multi-tier support (per-user, per-session, global). Thread-safe, zero-dependency, with automatic stale-bucket cleanup.
Abuse Detection
Detects hostile output, unhinged persona, jailbreak success, and persona deviation. Keyword heuristics by default, embedding-based cosine similarity with forcefield[ml].
Tool Governance
Policy-driven tool call security with pre-call and post-call inspection. Configurable allow/block/require-approval policies, secret and PII detection in tool results.
Command Scanning
Classify terminal commands for 22 dangerous patterns: rm -rf, curl | sh, chmod 777, reverse shells, credential exfiltration, privilege escalation, crontab persistence, and more. Powers Sentinel Mode in the VS Code extension.
Filename Scanning
Detect dangerous file operations on 12 sensitive file patterns: .env, id_rsa, secrets.json, authorized_keys, .pem, shadow, and more. Flags create, delete, and rename operations by severity.
Protected Paths
Designate files and folders as immutable. ProtectedPathSet supports exact, glob, and directory-recursive matching. Integrates with VS Code Sentinel Mode to block agent modifications to critical files.
Drop-In Integrations
from forcefield.integrations.openai import SafeOpenAI
client = SafeOpenAI() Wraps the OpenAI client. Scans prompts before sending, moderates responses after.
from forcefield.integrations.fastapi import ForceFieldMiddleware
app.add_middleware(ForceFieldMiddleware) ASGI middleware that scans all incoming request bodies automatically.
from forcefield.integrations.langchain import ForceFieldCallbackHandler
callbacks = [ForceFieldCallbackHandler()] Callback handler that scans prompts and outputs at every chain step.
CLI Tools
$ forcefield scan "your text here" Scan a single prompt from the terminal $ forcefield selftest Run 121 built-in attack prompts and verify detection $ forcefield test https://your-api.com/chat Red-team your LLM endpoint with 50+ attacks $ forcefield audit policy.yaml Validate your security policy configuration $ forcefield scan-command "rm -rf /" Classify a terminal command for dangerous patterns $ forcefield scan-filename .env --operation delete Check if a file operation is dangerous GitHub Action
Add ForceField to your CI/CD pipeline. Scans your codebase for prompt injection, PII leaks, and security vulnerabilities on every push.
- uses: Data-ScienceTech/forcefield@v0.5.1
with:
mode: 'both'
sensitivity: 'medium' Optional Extras
forcefield[ml] ONNX Runtime + sentence-transformers for ML detection and embedding-based abuse detection forcefield[cloud] Cloud hybrid scoring via ForceField Gateway API forcefield[langchain] LangChain callback handler integration forcefield[fastapi] FastAPI middleware integration forcefield[all] Everything above in one install Secure your AI app today
Install Open ForceField in seconds. No API keys required. Start detecting prompt injection, PII leaks, and LLM attacks immediately.