Local-first runtime governance layer for AI systems
Project description
๐ก๏ธ Guardian Runtime
The local-first AI firewall for developers.
Cut LLM token costs ยท Block data leaks ยท Stop jailbreaks โ all on your machine.
Guardian Runtime is a Python SDK that acts as a transparent security layer between your AI application and any LLM provider. It automatically compresses prompts to reduce token costs, blocks PII and API key leaks before they reach the model, and catches jailbreak attempts โ all running locally on your machine. Your prompts never leave your infrastructure.
Your Prompt
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ GUARDIAN RUNTIME โ
โ โ
โ โโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ
โ โ Optimizer โ โ Input Guard โ โ
โ โ โ โ โ โ
โ โ -30~70% โโโโถโ PII ยท Secrets โ โ
โ โ tokens โ โ Jailbreaks โ โ
โ โโโโโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโ โ
โ โ Output Guard โ โ
โ โ Scans AI response for PII โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
Safe Response + Cost Report
๐ Quick Start
1. Install
pip install guardian-runtime
Requires Python 3.10+. Includes the document converter (PDF/DOCX โ Markdown) out of the box.
2. Set your API key
export GEMINI_API_KEY="your-google-ai-studio-key" # free tier works!
3. Create a policy file (policy.yaml)
version: "1.0"
agents:
default:
llm:
provider: gemini
default_model: gemini-2.5-flash
input_guard:
pii_detection: true
jailbreak_detection: true
pii_action: block
output_guard:
pii_detection: true
optimizer:
enabled: true
whitespace_normalization: true
max_history_messages: 10
cost:
max_input_tokens: 8000
4. Use it
from guardian import Guardian
guardian = Guardian.from_policy("policy.yaml")
response = guardian.complete(
messages=[{"role": "user", "content": "Summarize this document for me."}]
)
print(response.content) # safe, validated response
print(response.input_tokens) # tokens consumed
print(response.estimated_cost_usd) # cost in USD
print(response.optimization) # token savings breakdown
โจ Why Guardian?
Observability tools (Langfuse, LangSmith, Helicone) log what went wrong โ after it happened.
Guardian stops it before it happens, on your machine.
| Observability Tools | Guardian Runtime | |
|---|---|---|
| When it acts | After the LLM call | Before and after |
| Your data | Sent to their cloud | Stays on your machine |
| PII in prompt | Logged | Blocked |
| Exposed API keys | Not detected | Blocked |
| Token costs | Tracked | Actively reduced |
| Jailbreak attempts | Logged | Blocked |
๐ Supported Providers
Works out-of-the-box with the Big 3 LLM providers:
| Provider | Environment Variable | Default Model |
|---|---|---|
| Google Gemini | GEMINI_API_KEY |
gemini-2.5-flash |
| Anthropic Claude | ANTHROPIC_API_KEY |
claude-3-5-haiku-latest |
| OpenAI | OPENAI_API_KEY |
gpt-4o-mini |
Override provider at runtime:
response = guardian.complete(
provider="anthropic",
model="claude-sonnet-4-20250514",
messages=[...]
)
๐ก๏ธ Security & Privacy Features
PII Detection
Detects and blocks sensitive personal data with specialized patterns:
| Category | Detected Entities |
|---|---|
| India (DPDP Act) | Aadhaar (xxxx xxxx xxxx), PAN (XXXXX0000X), UPI (name@bank) |
| Global | SSN, Credit Cards, Email, Phone, Passport |
| Action modes | block, redact, or flag per entity type |
Secret Leak Prevention
Stops developers from accidentally sending credentials to an LLM:
- OpenAI keys (
sk-...) ยท AWS access keys (AKIA...) ยท GitHub tokens (ghp_...) - Stripe keys (
sk_live_...) ยท Razorpay keys (rzp_live_...) ยท Groq keys (gsk_...) - Generic
.envvariable patterns
Jailbreak Detection
40+ regex patterns covering:
- DAN variants and instruction overrides
- Role-play injections and encoding tricks
- System prompt extraction attempts
Output Guard
Scans LLM responses for PII and secrets before they reach your users.
๐ Cost Optimization
| Feature | How it saves |
|---|---|
| Prompt Compression | Strips redundant whitespace, deduplicates system prompts, removes empty messages |
| History Trimming | Keeps last N turns, always preserves system prompt |
| Document Conversion | PDF, DOCX, XLSX, PPTX โ clean Markdown (30โ70% token savings) |
| Token Budget Enforcement | Warn or block when input exceeds your defined limit |
| Cost Estimation | Every response includes token count and USD cost estimate |
๐ Analysis Report
Every guardian.complete() call returns a full analysis:
response = guardian.complete(messages=[...])
print(response.content) # safe, validated response
print(response.blocked) # True if blocked
print(response.violations) # list of what was caught
print(response.input_tokens) # tokens used
print(response.estimated_cost_usd) # cost in USD
print(response.optimization) # tokens saved, savings %
Example optimization result:
{
"original_tokens": 1840,
"optimized_tokens": 620,
"savings_pct": 0.66,
"actions_taken": ["whitespace_normalization", "history_trimming"]
}
โ๏ธ Compliance Coverage
Guardian's detection covers major data protection regulations:
| Regulation | Coverage |
|---|---|
| India DPDP Act 2023 | Aadhaar, PAN, UPI โ native patterns |
| GDPR (EU) | Email, phone, passport, general PII |
| HIPAA (US Health) | Sensitive personal data blocking |
| CCPA (California) | Consumer data protection |
Note: Guardian is an assistive compliance tool, not legal advice. Always consult qualified counsel for regulatory requirements.
๐ฅ๏ธ CLI
Guardian comes with a built-in command line interface:
guardian init --key gdn_free_xxxxx # optional license setup
guardian validate policies/gemini.yaml # check policy syntax
guardian status # view usage, tokens, and costs
guardian logs --tail 20 # view recent violations
Example guardian status output:
License: not configured (offline free tier)
Plan: free
Checks this month: 1 / 10000
Status: ACTIVE
--- Usage Analytics ---
Original Input Tokens: 1,840
Optimized Input Tokens: 620 (-1,220 saved)
Total Output Tokens: 19
Estimated Cost: $0.000420 USD
๐๏ธ Local-First Architecture
Everything runs on your machine. Nothing is uploaded.
Your Machine
โโโ guardian SDK โ all processing happens here
โโโ ~/.guardian/
โ โโโ config.json โ license key (if using paid plan)
โ โโโ usage.json โ monthly check count
โ โโโ logs/ โ violation logs (never uploaded)
โ โโโ YYYY-MM-DD.jsonl
What Guardian's servers never receive:
- โ Your prompts
- โ Your LLM responses
- โ Your violation details
- โ Your API keys (OpenAI, Anthropic, etc.)
๐ Project Structure
guardian/
โโโ core/ engine, policy, models, storage
โโโ guards/ input guard, output guard, validators
โ โโโ validators/ pii, secrets, jailbreak, hallucination
โโโ optimizer/ prompt compression, document converter
โโโ providers/ openai, gemini, anthropic
โโโ finops/ token counter, cost calculator
โโโ proxy/ localhost reverse proxy server
โโโ logging/ local JSONL logger
โโโ dashboard/ usage dashboard
โโโ cli/ init, validate, status, logs
๐งช Development
git clone https://github.com/ashp15205/guardian-runtime.git
cd guardian-runtime
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest tests/ -q # 111 tests
See ARCHITECTURE.md for the full technical specification.
๐ Privacy
- All scanning runs on your infrastructure
- Logs stored locally at
~/.guardian/logs/ - Optional license sync sends only a hashed key + check count โ never prompts or responses
Built with โค๏ธ for developers who care about AI safety and cost.
PyPI ยท GitHub
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file guardian_runtime-0.2.4.tar.gz.
File metadata
- Download URL: guardian_runtime-0.2.4.tar.gz
- Upload date:
- Size: 89.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06310e8f9c39c8b9f37249eae0de4ac32afbb7984a6ef5b19dfbb6aaa3f8c706
|
|
| MD5 |
89b7c0c1a7e04a9610a7b2b69c35f5e2
|
|
| BLAKE2b-256 |
830e2702caa43163f48549e78c4f43e08186bca07c5969a22cd4cf5bdeae54fb
|
File details
Details for the file guardian_runtime-0.2.4-py3-none-any.whl.
File metadata
- Download URL: guardian_runtime-0.2.4-py3-none-any.whl
- Upload date:
- Size: 50.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25152561b1f3c1259df0fccb8a00c81b291120792a8cd15f3345e31053a35513
|
|
| MD5 |
0b7e7ea04b2118ad3a7ed77d51f9b53b
|
|
| BLAKE2b-256 |
f2fdadb61b9a648d8f73e4c58d01e86327a5f91b33fe4af82c309542ab359b91
|