Local-first runtime governance layer for AI systems
Project description
Guardian Runtime
A Zero-Latency FinOps & Security Firewall for AI Applications.
Intercept every prompt and response locally. Stop data leaks and runaway token costs.
๐ Website & Docs: https://ashp15205.github.io/guardian-runtime/
๐ฆ Available on PyPI: https://pypi.org/project/guardian-runtime/
๐ Table of Contents
- ๐ The Core Problem: Why You Need Guardian
- ๐ข The Solution: What is Guardian Runtime?
- ๐ Architecture
- ๐ Quickstart & Installation
- ๐ฏ Comprehensive Use Cases (Where & How to Use)
- ๐ป Complete CLI Command Reference
- โ๏ธ Advanced Configuration (Policy YAML)
- ๐ License
๐ The Core Problem: Why You Need Guardian
As AI coding agents (Claude Code, Cursor, Aider) become standard developer tools, they introduce two massive, hidden risks, and one regulatory headache:
๐ธ 1. The FinOps Risk: Cost Runaways
Autonomous agents operate in loops. If an agent gets stuck retrying a bug fix or accidentally dumps a massive 1GB log file into its context window, you can wake up to a $100 API bill overnight. The Problem: You have zero visibility or control over session costs until the provider's bill arrives at the end of the month.
๐ 2. The Security Risk: Data Exfiltration
Coding agents require full local codebase access to be useful. However, if you accidentally leave an AWS_SECRET_KEY or a database password in a .env file, the agent will silently upload it to a third-party LLM provider (OpenAI, Anthropic).
The Problem: Current observability tools (like Langfuse) only log the leak after the credentials have already reached the cloud.
๐ 3. The Compliance Risk (Briefly)
Sending unauthorized PII (like SSNs or emails in a test database) to foreign LLM APIs violates GDPR and DPDP regulations.
๐ข The Solution: Guardian Runtime
Guardian Runtime is a local-first security middleware and FinOps firewall. It runs entirely on your local machine and intercepts LLM traffic before it leaves your infrastructure.
| The Problem | How Guardian Solves It |
|---|---|
| Cost Runaways | Hard FinOps Budgets & Optimization: Tracks every token you spend locally. You can set a strict "$5.00 per day" limit. Passively compresses prompts (removing redundant whitespace and compressing PDFs) to save 20-60% on API costs. |
| Data Exfiltration | Zero-Latency Secret Scanners: Scans every prompt for API keys, AWS credentials, and secrets locally. If it detects a secret, it instantly drops the request before it reaches the internet. |
| Compliance | Local PII Blocking: Regex and ML scanners prevent PII from leaving your machine. |
๐ Architecture & The Security Pipeline
Guardian intercepts traffic at the network layer or via SDK, passing it through a strict verification pipeline before it ever reaches the cloud.
sequenceDiagram
participant User as Developer / Agent
participant Proxy as Guardian Runtime (Local)
participant Cloud as LLM Provider (OpenAI/Anthropic)
User->>Proxy: Sends prompt with codebase context
rect rgb(30, 41, 59)
Note over Proxy: 1. Input Guard (Security)
Proxy->>Proxy: Scan for AWS Keys, .env secrets
Proxy->>Proxy: Scan for PII (Regex + ML)
alt Threat Detected
Proxy-->>User: ๐จ HTTP 400: Request Blocked Locally
end
end
rect rgb(15, 23, 42)
Note over Proxy: 2. Token Optimizer (FinOps)
Proxy->>Proxy: Compress redundant whitespace
Proxy->>Proxy: Convert PDFs to clean Markdown
end
rect rgb(30, 41, 59)
Note over Proxy: 3. Budget Controller (FinOps)
Proxy->>Proxy: Check against $5.00 daily limit
alt Budget Exceeded
Proxy-->>User: ๐ธ HTTP 400: Daily Budget Exceeded
end
end
Proxy->>Cloud: Send Cleaned & Optimized Request
Cloud-->>Proxy: LLM Response
rect rgb(15, 23, 42)
Note over Proxy: 4. Output Guard (Auditor)
Proxy->>Proxy: Audit response for hallucinated secrets
end
Proxy-->>User: Safe Response Delivered
๐ Supported Integrations
Guardian Runtime acts as an HTTP proxy or a native Python SDK, meaning it integrates effortlessly with almost any modern AI tool without modifying their internal code.
- Visual IDEs: Cursor, Windsurf, VS Code (via Cline/RooCode)
- Terminal Agents: Claude Code, Aider, GitHub Copilot CLI
- Frameworks: LangChain, AutoGen, LlamaIndex, CrewAI
- LLM Providers: OpenAI, Anthropic, Google Gemini (via OpenAI compatibility layer)
๐ Quickstart & Installation
# Core framework only
pip install guardian_runtime
# Or install with specific LLM providers:
pip install "guardian_runtime[openai]"
pip install "guardian_runtime[anthropic]"
pip install "guardian_runtime[gemini]"
# Or install everything (Providers, ML Scanner, Document Converter):
pip install "guardian_runtime[all]"
Done. No signup, no keys, zero configuration required. All monitoring data stays on your local machine in ~/.guardian_runtime/.
๐ฏ Comprehensive Use Cases (Where & How to Use)
Guardian is designed to be universal. Here are the exact ways to deploy it based on your workflow.
1. Terminal Coding Agents (Claude Code, Aider)
Why use it here? CLI agents operate autonomously. They can accidentally read a .env file containing your production AWS keys and send it to Anthropic/OpenAI as context. Guardian prevents this and ensures the agent doesn't blow your budget.
How to use:
- Start the proxy in a background terminal:
guardian_runtime proxy --port 8080
- Tell your agent to route traffic through the proxy using environment variables:
In PowerShell:
$env:ANTHROPIC_BASE_URL="http://localhost:8080" claude
In Mac/Linux/Git Bash:export ANTHROPIC_BASE_URL=http://localhost:8080 claude
2. Visual IDEs (Cursor, Windsurf)
Why use it here? Modern GUI editors like Cursor have deep codebase access. While coding, you might highlight a file containing a secret and ask "explain this file". Guardian stops Cursor from sending that secret to the cloud.
How to use (Cursor Example):
- Start the proxy in your terminal:
guardian_runtime proxy --port 8080 - Open Cursor Settings (
Cmd/Ctrl + ,) - Navigate to Models > Override Base URL
- Set the Base URL to:
http://localhost:8080(Now all of Cursor's traffic is protected and tracked locally!)
3. Production Python Applications (SDK)
Why use it here? If you are building a production chatbot or RAG pipeline, you must ensure your users cannot perform "jailbreak" prompt injections or trick the LLM into leaking internal system prompts.
How to use: Use Guardian as a drop-in replacement for the OpenAI/Anthropic SDK.
import os
from guardian_runtime import GuardianRuntime, GuardianRuntimeBlockedError
os.environ["OPENAI_API_KEY"] = "sk-proj-..."
gr = GuardianRuntime() # Zero-config initialization
try:
# Protects user input before sending to OpenAI
response = gr.complete(
messages=[{"role": "user", "content": "My AWS Key is AKIAIOSFODNN7EXAMPLE"}],
raise_on_block=True
)
print(response.content)
except GuardianRuntimeBlockedError as e:
# Fails cleanly in your app instead of leaking the secret!
print(f"Blocked Locally: {e.response.violations[0].detail}")
4. Agentic Frameworks (LangChain, AutoGen)
Why use it here? Frameworks that spawn multiple communicating agents can rapidly consume tokens. Guardian acts as a central cost-tracking hub for all agent nodes.
How to use:
Point your framework's base_url to the local proxy.
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="gpt-4o",
base_url="http://localhost:8080", # Traffic routes through Guardian
api_key="sk-proj-..."
)
response = llm.invoke("Hello, Guardian!")
5. Data Prep for Web UIs (Document Conversion)
Why use it here? If you use the standard ChatGPT or Claude Web UI, uploading large PDFs eats up your context window quickly because PDFs contain massive amounts of hidden formatting bloat.
How to use: Use the built-in CLI to strip out formatting bloat and compress documents into pure Markdown before manually uploading them.
guardian_runtime convert massive_report.pdf --out cleaned_report.md
You can now upload cleaned_report.md to ChatGPT, saving huge amounts of context space and preventing hallucination.
๐ป Exhaustive CLI Command Reference
Guardian ships with a powerful suite of offline CLI tools. All data is stored purely locally in ~/.guardian_runtime/.
Below is a detailed dive into every command, its flags, and exactly how and why to use it.
guardian_runtime proxy (The Security Firewall)
Starts the local HTTP interception server. This is the core engine for protecting tools that you cannot edit the source code for (like Cursor or Claude Code).
Flags & Options:
--port, -p <int>: Port to listen on (Default:8080).--host <str>: Host to bind to. Use0.0.0.0to expose on your local network (Default:127.0.0.1).--policy <path>: Path to a custompolicy.yamlfile. If omitted, uses the default Zero-Config policy ($10 budget).--reload: Enables auto-reload if the policy file changes (useful for dev mode).
Example Usage:
$ guardian_runtime proxy --port 8080
โจ GuardianRuntime Runtime Proxy
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Listening on : http://127.0.0.1:8080
Policy : Default (Zero-Config)
Dashboard : guardian_runtime dashboard (run in another terminal)
Agent setup:
Claude Code โ ANTHROPIC_BASE_URL=http://localhost:8080 claude
Aider โ OPENAI_BASE_URL=http://localhost:8080 aider
Cursor โ Settings โ API Base โ http://localhost:8080
guardian_runtime convert <path> (Document Analysis)
Converts massive PDF, DOCX, and XLSX files into highly compressed, token-optimized Markdown.
Why use this? If you upload a raw PDF to a Web UI (like ChatGPT) or parse it in an agent, you waste thousands of tokens on hidden formatting bloat. This command strips the bloat before it hits the LLM context window.
Arguments & Flags:
<path>: The absolute or relative path to the document you want to compress.--out, -o <path>: Output file path for the converted Markdown. If omitted, prints a preview to the terminal.
Example Usage:
$ guardian_runtime convert massive_financial_report.pdf --out clean_report.md
โจ GuardianRuntime Document Converter
Processing: massive_financial_report.pdf...
โ Conversion Complete!
โข Original File: massive_financial_report.pdf
โข Token Count: 14,205
โข Saved to: clean_report.md
guardian_runtime scan <text> (Manual Threat Verification)
Performs a local security scan on a specific text string using the ML InputGuard and Regex scanners.
Why use this? Use this to verify exactly what the firewall will catch before you send a massive codebase to an agent, or if you want to test how sensitive the PII/Secret detection is.
Example Usage:
$ guardian_runtime scan "My AWS key is AKIAIOSFODNN7EXAMPLE"
๐ Scan failed! Threats detected:
- [HIGH] secret_detected: AWS Access Key ID found.
guardian_runtime analytics (FinOps Tracking)
Prints a beautiful terminal summary of today's API costs, token usage, and intercepted threats broken down by tool.
Flags:
--all: Shows all-time historical analytics instead of just today.
Example Usage:
$ guardian_runtime analytics
โจ GuardianRuntime Session Analytics (Today)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Claude Code
Cost: $2.3100
Requests: 54
Blocked: 3 (3 secret_detected)
Tokens: 82,000
Additional Administration Commands
guardian_runtime --help: Prints the global help menu listing all available commands and flags.guardian_runtime dashboard: Launches a beautiful React-based local Web UI tracking costs and threats on port 3000. It visualizes the analytics data with charts.guardian_runtime logs: Tails the local JSONL event stream in real-time (tail -f ~/.guardian_runtime/logs/events.jsonl). Perfect for debugging exactly why a specific prompt was blocked.guardian_runtime init: Generates a boilerplatepolicy.yamlfile in your current directory. Use this if you want to customize budgets, disable ML scanners, or enforce strict enterprise PII blocking.guardian_runtime validate: Checks yourpolicy.yamlfor syntax errors before you restart the proxy.guardian_runtime status: Shows the health of the local installation, ML models, and storage directory.guardian_runtime clean: Deletes your entire~/.guardian_runtimedirectory. Use this if you want to permanently delete all local analytics, logs, and custom policies.
โ๏ธ Advanced Configuration (Policy YAML)
Guardian Runtime is perfectly tuned out of the box with a $10 daily budget and strict secret scanning. If you need custom rules, run guardian_runtime init to create a policy.yaml:
version: "1.0"
agents:
default:
llm:
provider: openai
default_model: gpt-4o
input_guard:
scanner_enabled: true
jailbreak_detection: true
scanner_action: block
cost:
daily_budget: 5.00 # Instantly block if daily spend exceeds $5.00
max_input_tokens: 20000 # Block massive context windows to save money
๐ What happens when Guardian blocks a request?
Where will I see the block?
- If using the Proxy: You will see the block in the terminal running
guardian_runtime proxy, AND inside the UI of the tool you are using (e.g., Claude Code or Aider). - If using the Python SDK: It surfaces instantly in your standard Python server logs or terminal.
How is it blocked?
- Proxy Mode: Guardian returns a graceful
HTTP 400error with a clear message. This ensures CLI agents display a clean error message in their chat interface instead of crashing or freezing your session. - SDK Mode: Guardian raises a
GuardianRuntimeBlockedErrorexception that can be cleanly caught.
Example Block Message:
BadRequestError: ๐จ [SECRET_DETECTED] AWS key AKIAIOS... found. Request blocked locally.
๐ License
Released under the MIT License โ free to use, modify, and distribute. Zero tracking, zero cloud dependencies. Your code is yours.
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-1.0.11.tar.gz.
File metadata
- Download URL: guardian_runtime-1.0.11.tar.gz
- Upload date:
- Size: 74.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02aa7e39d763b7b50527e8311fe656ac96589f78e6e1c7e714ed3c2a4fbe66bf
|
|
| MD5 |
bddf7166ed7795de2400d5f163d832d2
|
|
| BLAKE2b-256 |
d9da9df0c963e0efc141b28b1a2f31c2a606a57a86918833ee733f3c9449a512
|
File details
Details for the file guardian_runtime-1.0.11-py3-none-any.whl.
File metadata
- Download URL: guardian_runtime-1.0.11-py3-none-any.whl
- Upload date:
- Size: 58.3 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 |
723dcb2e84af98cf09fed6e681b7aefa9a197298e63746ee72cd183048bce623
|
|
| MD5 |
8f5c4c3744ed168151960ab74456e0ec
|
|
| BLAKE2b-256 |
539753e2dc2007da79159b8964cabf1fc69ea171275d0ede78a61595881b63d4
|