Skip to content

About

Guardian Runtime sits securely on your machine, acting as a bodyguard for your code. Whenever you use AI tools like Cursor or Claude Code, it intercept every prompt and response locally to stop data leaks and runaway token costs. A zero-latency, local-first runtime firewall for LLMs.

Topics

Resources

Contributing

Stars

20 stars

Watchers

0 watching

Forks

Repository files navigation

Guardian Runtime

Local-first security and governance for AI applications

Guard the boundary between your agent and the cloud.

Version PyPI License

Guardian Runtime is an offline-first Python SDK and local HTTP gateway that inspects AI traffic before it reaches external model providers. It protects prompts, files, responses, budgets, and policy decisions without requiring a hosted service or changing your agent framework.

Quickstart · Why Guardian · Architecture · Policies · Contributing

News

  • 2026-11 — Strict policy validation, corrected examples, monthly/session budgets, and deterministic tool-policy foundations.
  • 2026-11 — 39 automated tests pass; Ruff, compilation, policy validation, dependency checks, and wheel builds are clean.
  • Next — Provider contract tests, safe logging, filesystem/shell adapters, and MCP governance.

Why Guardian

AI agents are useful because they can see context and take action. That also creates a security boundary:

Agent / coding assistant
        │ prompts · files · retrieved context · tool proposals
        ▼
Guardian Runtime  ← inspect · redact · block · budget · audit
        ▼
LLM provider / external service

Use Guardian when an agent can access credentials, personal data, large documents, paid model APIs, or external tools.

Situation Guardian helps with
Prompts contain credentials or personal data Detect and block or redact secrets and PII locally
An agent can run for hours Enforce input, daily, monthly, and session budgets
You use multiple providers Normalize OpenAI, Anthropic, and Gemini traffic behind one gateway
You work with large files Inspect code files and convert supported documents to Markdown
You need a local audit trail Record decisions, token usage, cost, and violations locally
You are building agent governance Start with strict YAML policies and deterministic tool decisions

What it is—and what it is not

Guardian is a governance layer, not an agent orchestrator. It does not replace Claude Code, Cursor, LangGraph, CrewAI, OpenAI Agents, or MCP. It sits beside them and enforces boundaries around their model traffic.

The stable surface today is the local LLM gateway and Python SDK. The tool-policy engine is the foundation for the next runtime layer; filesystem, shell, Git, and MCP execution adapters are planned integrations rather than completed features.

Core capabilities

Protect data before it leaves the machine

  • Secret detection for common cloud, Git, payment, and API credentials.
  • Offline PII detection for email, phone, SSN, Aadhaar, PAN, UPI, passport, and cards.
  • Optional Presidio-backed detection for broader PII coverage.
  • Line-aware violations with redaction or blocking policies.
  • Output checks for secrets and PII returned by a model.
  • Local logs with no default cloud telemetry.

Control model usage

  • OpenAI-compatible, Anthropic-compatible, and native Gemini proxy routes.
  • Token counting and safe cost estimates across providers.
  • Daily, monthly, per-session, and maximum-input-token limits.
  • Local spend ledger and usage analytics.
  • Prompt normalization, history trimming, and optional terse mode.

Establish deterministic action policy

The policy foundation supports model-independent allow, deny, and approval_required decisions, default-deny behavior, wildcard tool matching, and argument type/enum/regex validation.

How it works

Receive request → resolve policy → optimize/count → enforce limits
      → scan prompt/files → block, redact, flag, or forward
      → scan response → record local usage, cost, and decisions

Quickstart

Install

pip install guardian-runtime
pip install "guardian-runtime[openai]"      # optional provider SDK
pip install "guardian-runtime[anthropic]"   # optional provider SDK
pip install "guardian-runtime[gemini]"      # optional provider SDK

Start the gateway

guardian_runtime proxy --port 8080
# Claude Code
export ANTHROPIC_BASE_URL=http://localhost:8080
claude

# Aider and OpenAI-compatible clients
export OPENAI_API_BASE=http://localhost:8080/v1
aider

Python SDK

from guardian_runtime import GuardianRuntime, GuardianRuntimeBlockedError

guardian = GuardianRuntime()
try:
    result = guardian.complete(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": "Explain this function."}],
        raise_on_block=True,
    )
    print(result.content)
except GuardianRuntimeBlockedError as exc:
    print("Blocked:", exc.response.violations)

Policies

Policies are strict YAML files. Unknown or misspelled fields fail validation instead of being silently ignored.

version: "1.0"
name: "local-development"
interactive_mode: off
agents:
  default:
    llm:
      provider: openai
      default_model: gpt-4o-mini
    input_guard:
      scanner_enabled: true
      detect_entities: [secret, email, phone]
      scanner_action: block
      jailbreak_detection: true
    cost:
      daily_budget: 5.00
      monthly_budget: 50.00
      per_session_limit: 1.00
      max_input_tokens: 16000
    tools:
      default_action: deny
      allowed: [filesystem.read, git.diff]
      approval_required: [filesystem.write, shell.execute]
      denied: [git.push]
guardian_runtime validate policies/production.yaml

See policies/ for minimal, development, optimized, provider-specific, and production examples.

CLI

guardian_runtime --help
guardian_runtime init
guardian_runtime proxy --port 8080
guardian_runtime validate policies/dev.yaml
guardian_runtime scan "text to inspect"
guardian_runtime convert file.pdf --out file.md
guardian_runtime analytics
guardian_runtime dashboard

Integrations and scope

Surface Status
OpenAI, Anthropic, and native Gemini traffic Supported
Streaming responses Supported at engine/proxy level
Cursor, Windsurf, Aider, Claude Code Compatible through proxy configuration
LangChain, AutoGen, LlamaIndex, CrewAI Usable through HTTP or SDK integration
MCP server/tool governance Roadmap
Filesystem, shell, Git, and HTTP action adapters Roadmap
RAG provenance and retrieval policy Roadmap

Local data and privacy

Guardian stores state under ~/.guardian_runtime/ (usage.json, spend.jsonl, optional pricing.yaml, and logs/). Importing Guardian does not create pricing files or require cloud access. Configure logging carefully in production.

Roadmap

Reliability and compatibility

  • Provider contract tests for ordinary and streamed OpenAI, Anthropic, and Gemini traffic.
  • Proxy authentication, request limits, safe errors, and correlation IDs.
  • Redaction guarantees for logs, dashboards, and exceptions.
  • Implement or remove currently declared but unenforced options such as loop detection and automatic model downgrade.

Agent action firewall

  • Filesystem, shell, Git, HTTP, and database adapters.
  • Capability-based agent identity.
  • Risk-based approvals, step limits, and action budgets.

MCP and RAG governance

  • MCP discovery, server inspection, tool-schema analysis, and proxying.
  • Tool argument and destination policies.
  • RAG source provenance, access-aware retrieval, memory isolation, and poisoning signals.
  • OpenTelemetry-compatible traces for model calls, retrieval, guardrails, approvals, and tool execution.

Security model

Guardian is defense in depth, not a guarantee that a model cannot be manipulated. Prompt injection is not reliably solved by pattern matching alone. Durable controls are least privilege, data provenance, deterministic authorization, sandboxing, output validation, and auditability.

Please report security issues privately through the repository’s security process. Do not publish credentials, exploit details, or sensitive prompts in public issues.

Development

git clone https://github.com/ashp15205/guardian-runtime.git
cd guardian-runtime
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest -q
ruff check guardian_runtime tests
python3 -m compileall -q guardian_runtime

The local handoff file report.md is intentionally ignored by Git and may be used to record checkpoint state for another agent.

Contributing

Good first contributions include provider compatibility tests, security regression fixtures, safe logging tests, policy examples, filesystem/shell adapters with explicit sandbox boundaries, and MCP interoperability tests.

Before opening a pull request, run the complete test and lint commands above. Security-sensitive changes should include a regression test and explain which data or action boundary they protect.

License

Guardian Runtime is released under the MIT License.

About

Guardian Runtime sits securely on your machine, acting as a bodyguard for your code. Whenever you use AI tools like Cursor or Claude Code, it intercept every prompt and response locally to stop data leaks and runaway token costs. A zero-latency, local-first runtime firewall for LLMs.

Topics

Resources

Contributing

Stars

20 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages