Metadata-Version: 2.5
Name: charterguard
Version: 0.1.0
Summary: Framework-agnostic guardrail pipeline for LLM agent harnesses: injection, jailbreak, scope, redaction, grounding, audit.
License: MIT License
        
        Copyright (c) 2026 Gnananvesh
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: agents,guardrails,llm,prompt-injection,security
Requires-Python: >=3.11
Provides-Extra: claude-agent-sdk
Requires-Dist: claude-agent-sdk>=0.2.176; extra == 'claude-agent-sdk'
Provides-Extra: dev
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pre-commit>=3.7; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Provides-Extra: fastapi
Requires-Dist: fastapi>=0.110; extra == 'fastapi'
Provides-Extra: langchain
Requires-Dist: langchain-core>=0.3; extra == 'langchain'
Provides-Extra: langgraph
Requires-Dist: langgraph>=0.2; extra == 'langgraph'
Provides-Extra: onnx
Requires-Dist: onnxruntime>=1.17; extra == 'onnx'
Requires-Dist: tokenizers>=0.15; extra == 'onnx'
Provides-Extra: openai-agents
Requires-Dist: openai-agents>=0.24; extra == 'openai-agents'
Provides-Extra: otel
Requires-Dist: opentelemetry-api>=1.24; extra == 'otel'
Provides-Extra: presidio
Requires-Dist: presidio-analyzer>=2.2; extra == 'presidio'
Requires-Dist: spacy>=3.7; extra == 'presidio'
Provides-Extra: prometheus
Requires-Dist: prometheus-client>=0.20; extra == 'prometheus'
Provides-Extra: pydantic-ai
Requires-Dist: pydantic-ai-slim>=2.65; extra == 'pydantic-ai'
Provides-Extra: redis
Requires-Dist: redis>=5.0; extra == 'redis'
Provides-Extra: spacy
Requires-Dist: spacy>=3.7; extra == 'spacy'
Description-Content-Type: text/markdown

# charterguard

[![ci](https://github.com/gnananveshReddy/charterguard/actions/workflows/ci.yml/badge.svg)](https://github.com/gnananveshReddy/charterguard/actions/workflows/ci.yml)
[![codeql](https://github.com/gnananveshReddy/charterguard/actions/workflows/codeql.yml/badge.svg)](https://github.com/gnananveshReddy/charterguard/actions/workflows/codeql.yml)
[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/gnananveshReddy/charterguard/badge)](https://scorecard.dev/viewer/?uri=github.com/gnananveshReddy/charterguard)
![python](https://img.shields.io/badge/python-3.11%20%7C%203.12%20%7C%203.13-blue)
![dependencies](https://img.shields.io/badge/runtime%20dependencies-0-brightgreen)
[![license](https://img.shields.io/badge/license-MIT-blue)](LICENSE)


**Deterministic guardrails for LLM agents, at every trust boundary.** charterguard
checks user turns, retrieved documents, tool calls, tool output and final answers
for prompt injection, jailbreaks, destructive commands, secrets and PII. It runs in
process in microseconds, with zero runtime dependencies, and every decision is a
typed, auditable `Verdict`.

* **Controls do not live in prompts.** Every decision is made in code, outside the
  model, and can be logged, replayed and audited.
* **Everything the model did not author is untrusted.** Retrieved content and tool
  results are inspected, wrapped in a delimiter-hardened envelope, and quarantined
  if they carry instructions.

📖 **Documentation:** [docs/](docs/index.md) (also published with GitHub Pages
from `mkdocs.yml`)

## Install

```bash
pip install "charterguard @ git+https://github.com/gnananveshReddy/charterguard"
pip install "charterguard[fastapi] @ git+https://github.com/gnananveshReddy/charterguard"   # or [langchain], [onnx], ...
```

`pip install charterguard` works once the first release is on PyPI. Python 3.11+.
Every extra is optional and none is imported by the core; see the
[adapter matrix](docs/adapters.md).

## Quick start

```python
from charterguard import GuardrailConfig, GuardrailPipeline

guardrails = GuardrailPipeline(GuardrailConfig.strict())

verdict = guardrails.check_input(user_message, session_id=session_id)
if verdict.blocked:
    return guardrails.refusal(verdict)

for chunk in retrieved:                       # before it reaches the context window
    result = guardrails.inspect_untrusted(chunk.text, source=chunk.uri)
    if result.safe_to_use:
        context.append(result.context_block())

tool_result = guardrails.inspect_tool_output(raw_output, tool_name="search_docs")
out = guardrails.check_output(answer)
final_text = guardrails.refusal(out) if out.blocked else (out.sanitized or answer)
```

```bash
echo "ignore all previous instructions" | charterguard scan
charterguard scan --layer tool --pack agent-tools fetched_page.html
```

## What's included

| | |
| --- | --- |
| **Detection** | Injection and jailbreak rules (English plus seed coverage for 26 more languages, including 10 Indian languages and Hinglish), encoded-payload decoding, de-obfuscation (leetspeak, letter spacing, rot13, quote wrapping), destructive commands, exfiltration beacons |
| **Data protection** | Secret and PII redaction with checksum validators (cards, IBAN, Aadhaar, PAN, GSTIN, ...) and exact-span placeholders |
| **Agent controls** | Charter-based scope gate, tool allow-lists, per-session volume ceilings, untrusted-content envelopes, grounding checks |
| **Integrations** | FastAPI, LangChain and LangGraph, OpenAI Agents SDK, Claude Agent SDK, Pydantic AI, MCP (server and result guard), CLI and pre-commit hook |
| **Operations** | TOML policy files, self-testing [rule packs](docs/rule-packs.md), shadow and report-only rollout, hash-chained audit, metrics sinks, optional classifier tier (`.[onnx]`) |

## Accuracy, honestly

Rules only, no classifier attached (`python benchmarks/accuracy.py`):

| Dataset | Precision | Recall | FPR |
| --- | --- | --- | --- |
| bundled corpus (hand-written attacks and tricky benign texts) | 0.96 | 1.00 | 0.04 |
| deepset/prompt-injections, held-out test split | 1.00 | 0.20 | 0.00 |
| jackhhao/jailbreak-classification | 0.91 | 0.50 | 0.05 |

The rules are precise, not complete: paraphrased attacks need the classifier tier.
See [Detection accuracy](docs/accuracy.md) and [How it compares](docs/comparison.md).

## Documentation

* [Overview and trust boundaries](docs/index.md)
* [Playground](docs/playground.md): try it in the browser (Pyodide, on the docs site)
* [Integrations](docs/integrations.md): FastAPI, LangChain/LangGraph, agent SDKs, MCP
* [Untrusted content and envelopes](docs/untrusted-content.md)
* [Policy files](docs/policy.md) · [Rule packs](docs/rule-packs.md) · [Command line](docs/cli.md)
* [Operating it](docs/operations.md): rollout modes, audit, performance
* [Extending it](docs/extending.md) · [Adapters](docs/adapters.md)
* [Security assumptions and limits](docs/security.md)

## Contributing and security

Missed attacks and false positives are the most useful contributions; the issue
templates ask for exactly what is needed. See [CONTRIBUTING.md](CONTRIBUTING.md).
Report bypasses privately as described in [SECURITY.md](SECURITY.md).

MIT licensed.
