Metadata-Version: 2.4
Name: guardian-runtime
Version: 1.0.6
Summary: Local-first runtime governance layer for AI systems
Project-URL: Homepage, https://ashp15205.github.io/guardian-runtime/
Project-URL: Documentation, https://ashp15205.github.io/guardian-runtime/
Project-URL: Repository, https://github.com/ashp15205/guardian-runtime
Author-email: Ashish Patil <ashishtp2005@gmail.com>
License-File: LICENSE
Keywords: ai,anthropic,claude,dpdp,finops,gemini,governance,guardrails,jailbreak,langchain,llm,openai,pii
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Requires-Dist: anthropic>=0.40
Requires-Dist: click>=8.0
Requires-Dist: fastapi>=0.100
Requires-Dist: google-genai>=0.8.0
Requires-Dist: httpx>=0.25
Requires-Dist: markitdown[all]>=0.0.1
Requires-Dist: openai>=1.0
Requires-Dist: pydantic>=2.0
Requires-Dist: pyyaml>=6.0
Requires-Dist: tiktoken>=0.5
Requires-Dist: uvicorn>=0.23
Provides-Extra: all
Requires-Dist: langchain-core>=0.1; extra == 'all'
Requires-Dist: presidio-analyzer>=2.2; extra == 'all'
Requires-Dist: presidio-anonymizer>=2.2; extra == 'all'
Provides-Extra: dev
Requires-Dist: mypy>=1.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
Requires-Dist: pytest-mock>=3.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff>=0.1; extra == 'dev'
Provides-Extra: langchain
Requires-Dist: langchain-core>=0.1; extra == 'langchain'
Provides-Extra: presidio
Requires-Dist: presidio-analyzer>=2.2; extra == 'presidio'
Requires-Dist: presidio-anonymizer>=2.2; extra == 'presidio'
Description-Content-Type: text/markdown

<p align="center">
  <img src="https://img.shields.io/badge/GuardianRuntime-Local%20AI%20Firewall-00ff88?style=for-the-badge&logo=shield&logoColor=black" alt="GuardianRuntime" />
</p>

<h1 align="center">Guardian Runtime</h1>

<p align="center">
  <strong>A Zero-Latency FinOps & Security Firewall for AI Applications.<br>
  Intercept every prompt and response locally. Stop data leaks and runaway token costs.</strong>
</p>

<p align="center">
  <a href="https://pypi.org/project/guardian-runtime/"><img src="https://img.shields.io/pypi/v/guardian-runtime.svg?style=for-the-badge&color=00ff88&logo=pypi&logoColor=white" alt="PyPI Version"></a>
  <a href="https://pypi.org/project/guardian-runtime/"><img src="https://img.shields.io/pypi/pyversions/guardian-runtime.svg?style=for-the-badge&logo=python&logoColor=white" alt="Python Versions"></a>
  <a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue?style=for-the-badge" alt="MIT License"></a>
  <img src="https://img.shields.io/badge/no%20signup-no%20API%20key-00ff88?style=for-the-badge" alt="No signup required">
  <img src="https://img.shields.io/badge/100%25-local%20execution-00ff88?style=for-the-badge" alt="100% Local">
</p>

<p align="center">
  🌐 <strong>Website & Docs:</strong> <a href="https://ashp15205.github.io/guardian-runtime/">https://ashp15205.github.io/guardian-runtime/</a><br>
  📦 <strong>Available on PyPI:</strong> <a href="https://pypi.org/project/guardian-runtime/">https://pypi.org/project/guardian-runtime/</a>
</p>

---

## 🛑 The Problem: Developers are Flying Blind

1. **The Cost Risk:** CLI coding agents (Claude Code, Cursor, Aider) run autonomously. If they get stuck in an infinite retry loop or parse a massive log file, you wake up to a **$50 API bill**. You have zero visibility into session costs until the bill arrives.
2. **The Security Risk:** Coding agents have full access to your workspace. If you accidentally leave an `AWS_SECRET_KEY` or `.env` credential in a file, the agent will silently upload it to a third-party LLM provider.

## 🟢 The Solution: A Developer-First Local Firewall

**Guardian Runtime** is a zero-latency FinOps and Security firewall. It runs entirely on your local machine and sits directly between your coding agents and the LLM provider.

- **Session Analytics & Hard Budgets**: Automatically tracks tokens and costs per session via the CLI. It sets a hard $10/day default limit so infinite loops never drain your credit card.
- **Local Secret Scanning**: Instantly intercepts and blocks API keys, AWS credentials, and `.env` secrets from ever leaving your local machine.
- **Zero Config**: No complex policies required. It protects your budget and secrets out of the box.

---

## ⚡ Key Features

1. **💰 Custom Hard Budgets**: Configure a strict daily budget so runaway agents can't drain your API credits.
2. **🔑 Secret & Credential Firewall**: Catches hardcoded API keys (AWS, Stripe, OpenAI, GitHub) before they leave your laptop. 
3. **📉 Token Optimizer**: Compresses redundant whitespace and reduces prompt bloat to passively save you money.
4. **🌐 Universal Local Proxy**: Works seamlessly with CLI agents like Anthropic Claude Code and Aider.
5. **🏴‍☠️ Unsafe Command Defense**: Stops adversarial prompts from hijacking your agent to run malicious CLI commands.
6. **📊 Built-in Local Dashboard**: Tracks every intercepted threat and every cent spent locally in `~/.guardian_runtime/logs/` with a beautiful offline dashboard.

---

## 🏗 Architecture

```text
       👤 USER INPUT / APP LOGIC
                 │
                 ▼
 ┌──────────────────────────────────────┐
 │   GUARDIAN RUNTIME (Local Proxy)     │
 │                                      │
 │  1. Input Guard (Secret Scanner)     │ ──(Blocks Threats)
 │  2. Token Optimizer                  │ ──(Reduces Cost)
 │  3. FinOps Limits                    │ ──(Enforces Budgets)
 └───────────────┬──────────────────────┘
                 │ (Cleaned & Optimized)
                 ▼
      ☁️ LLM API (OpenAI/Anthropic)
                 │
                 ▼
 ┌──────────────────────────────────────┐
 │  GUARDIAN RUNTIME (Local Proxy)      │
 │                                      │
 │  1. Output Guard (Auditor)           │ ──(Flags Secrets)
 └───────────────┬──────────────────────┘
                 │ (Safe Response)
                 ▼
           💻 USER SCREEN
```

---

## 🚀 Quickstart

### Installation

```bash
pip install guardian-runtime
```
Done. No signup, no keys, zero configuration required.

### Integration Methods

Guardian can be used as a drop-in **Python SDK** or as a **Local HTTP Proxy** for tools you can't edit.

#### Case 1: Custom Python Application (SDK)
Replace your direct LLM calls with the `GuardianRuntime` wrapper. Works instantly with zero configuration.

```python
import os
from guardian_runtime import GuardianRuntime, GuardianRuntimeBlockedError

os.environ["OPENAI_API_KEY"] = "sk-proj-..."

# Zero-config initialization
gr = GuardianRuntime()

try:
    response = gr.complete(
        messages=[{"role": "user", "content": "My AWS Key is AKIAIOSFODNN7EXAMPLE"}],
        raise_on_block=True
    )
    print(response.content)
except GuardianRuntimeBlockedError as e:
    print(f"Blocked Locally: {e.response.violations[0].detail}")
```

#### Case 2: Claude Code & CLI Assistants
For CLI tools like Anthropic's Claude Code, start the proxy and override the base URL.

```bash
# 1. Start the proxy in a background terminal
guardian_runtime proxy --port 8080

# 2. Tell Claude to route traffic through Guardian
export ANTHROPIC_BASE_URL=http://localhost:8080
claude
```

#### Case 3: Cursor IDE (Coming Soon)
We are actively working on full support for Cursor's AI Chat and Composer.

1. Start the proxy: `guardian_runtime proxy --port 8080`
2. Open Cursor Settings (Cmd+,)
3. Go to **Models > Override Base URL**
4. Set it to: `http://localhost:8080` *(Note: May exhibit unstable behavior in current version)*

#### Case 4: Agentic Frameworks (LangChain / AutoGen)
Building autonomous agents? Guardian acts as a security middleware for any standard LLM client.

```python
from langchain_openai import ChatOpenAI

# Point LangChain to the Guardian Proxy
llm = ChatOpenAI(
    model="gpt-4o",
    base_url="http://localhost:8080"
)
```

#### Case 5: Document Analysis (RAG)
Heavy PDFs contain massive amounts of formatting bloat. Use the Document Converter to clean and compress them before the LLM sees them.

```python
from guardian_runtime import convert_document

doc = convert_document("financial_report.pdf")
print(doc.token_count) # See exactly how much context it uses
print(doc.content)     # Feed pure Markdown to your RAG
```

---

## 🛑 What happens when Guardian blocks a request?

When Guardian detects a Secret or a Budget Violation, it halts the request immediately. 

**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 400/403` error. 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 `GuardianRuntimeBlockedError` exception that can be cleanly caught in a standard `try/except` block.

**What will I see?**
You will see a completely transparent, actionable error message. No obscure stack traces.
* Example (Budget): `BadRequestError: 🚨 [BUDGET_EXCEEDED] Daily budget of $10.00 exceeded.`
* Example (Secret): `Error: HTTP 403. 🚨 [SECRET_DETECTED] AWS key AKIAIOS... found.`

---

## ⚙️ Advanced Configuration (Optional)

Guardian Runtime works perfectly out of the box for independent developers. But if you want to customize strict budgets or scan for custom secrets, you can create an optional `policy.yaml`:

```bash
guardian_runtime init
```

```yaml
version: "1.0"
name: "production"
interactive_mode: off

agents:
  default:
    llm:
      provider: openai
      default_model: gpt-4o

    input_guard:
      scanner_enabled: true
      jailbreak_detection: true
      scanner_action: block 

    optimizer:
      enabled: true
      whitespace_normalization: true
      
    cost:
      daily_budget: 10.00       # Instantly blocks if daily spend exceeds $10.00
      max_input_tokens: 50000   # Instantly blocks massive context windows
      max_output_tokens: 4000
```

---

## 🔍 Output Auditing (Non-Blocking)

By default, the **Input Guard** acts as a strict firewall—blocking requests containing secrets before they cost you money. 

The **Output Guard**, however, acts as an **Auditor**. If an LLM accidentally hallucinates an internal API key in its response, Guardian will *not* drop the response. Instead, it passes the message back to your application but attaches a list of `violations` to the response object. This allows your application to handle the mistake gracefully on the frontend.

---

## 📈 CLI Tools & Dashboard

Guardian ships with built-in tools for local observability. All logs are stored strictly on your local machine in `~/.guardian_runtime/logs/`.

```bash
# View live intercepted traffic
guardian_runtime logs --tail 20

# View Session Analytics (Cost & Tokens per CLI tool)
guardian_runtime analytics

# Launch the full local FinOps & Security dashboard
guardian_runtime dashboard
```

**Example Analytics Output:**
```text
  ⛨  GuardianRuntime Session Analytics (Today)
  ──────────────────────────────────────────────

  Claude Code
  Cost:       $2.3100
  Requests:   54
  Blocked:    3 (3 secret_detected)
  Tokens:     82,000
```

---

## 📜 License

Released under the **MIT License** — free to use, modify, and distribute. Zero tracking, zero cloud dependencies.
