Metadata-Version: 2.4
Name: breachguard
Version: 0.1.0
Summary: Empower Your Security Testing Quickly — adversarial testing for AI agents with tool interception
Keywords: security,prompt-injection,llm,agent,testing,red-team,policy
License-Expression: MIT
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Testing
Classifier: Typing :: Typed
Requires-Dist: httpx>=0.28.1
Requires-Dist: pydantic>=2.14.2
Requires-Dist: rich>=15.0.0
Requires-Dist: typer>=0.27.3
Requires-Python: >=3.11
Project-URL: Homepage, https://github.com/MaruthiCharan2403/breachguard
Project-URL: Repository, https://github.com/MaruthiCharan2403/breachguard
Project-URL: Issues, https://github.com/MaruthiCharan2403/breachguard/issues
Description-Content-Type: text/markdown

# BreachGuard

BreachGuard generates tailored prompt-injection test cases, executes them through a user-supplied agent runner, intercepts and evaluates tool calls against policies, and exports reproducible failures. It is a typed Python library and CLI (v0.1.0) for AI-agent security testing: you declare tools and policies, seed or LLM-generate attacks with your own provider key, run isolated sessions that never execute intercepted tools by default, and get terminal/JSON/HTML reports plus pytest regressions with CI-friendly exit codes.

## Features

### Typed definitions for tools, policies, fixtures, and runners
Declare what the agent under test may do with `ToolSchema` / `define_tool`, `Policy` / `define_policy` / `deny_tool` / `deny_argument_substring` / `deny_sequence`, and `define_fixture` / `FixtureBundle`. Plug in any agent via the `AgentRunner` protocol (`run(prompt, tools) -> str`) or adapters (`CallableRunner`, `DictMessageRunner`, `AttributeAgentRunner`, `OpenAIToolsRunner`, `ScriptedRunner`). Main actions: build schemas in Python, or write a fixture JSON and validate it with `breachguard validate-fixture`.

### Seeded and LLM-backed attack generation
`AttackGenerator` produces direct, indirect, obfuscated, and multi-step cases (`INJECTION_KINDS`) from your tools and policy. Seeded generation is offline and deterministic; LLM generation uses **your** OpenAI-compatible API key via `AttackGenerator.with_llm` / `AttackGenerationConfig` (CLI: `breachguard generate --llm --api-key …`). Hand-authored cases use `hand_authored_case` or `CaseSet.add_hand_authored`. Main actions: `breachguard init-fixtures`, then `breachguard generate --fixture … --output …`.

### Tool-call interception and policy evaluation
`Interceptor` records every tool invocation before execution, evaluates names (fnmatch), arguments (forbidden keys/substrings), and call sequences (`evaluate_call` / `evaluate_sequence` / `evaluate_policy`), and blocks by default (`execute_tools=False`). Deny-action hits prevent real side effects unless you explicitly opt in. Main actions: run a `TestSession`, or call `interceptor.intercept(name, args)` / `bind_schemas` from the library.

### Isolated, repeatable test sessions
`TestSession` + `SessionOptions` filter by case id, tag, or kind; give each case a fresh interceptor; support fixed `session_id` for comparable reruns; and accept `rerun(..., runner=…, prompt_overrides=…)` when prompts or agent config change. `CaseSet` merges seeded and hand-authored cases and applies filters/overrides. Main actions: `session.run(cases)` in Python, or `breachguard run --fixture … --case-id … --tag …`.

### Reports (terminal, JSON, HTML) with reproduction details
`write_report` / `render_terminal` / `render_json` / `render_html` include attack inputs, observed tool calls, violated policies, and reproduction hints (`reproduction_commands`). Brand colours (`#003C30` / `#00BFAE`) appear in HTML. CLI: `breachguard run --format terminal|json|html [--output path]`.

### Pytest export and CI exit codes
`findings_to_pytest` / `write_pytest_export` turn violations into a parametrized pytest module that replays scripted tool calls. `ci_exit_code(report)` / `SessionReport.exit_code` return `0` when clean and `1` on violations or agent failures. CLI: `breachguard run … --export-pytest path` (process exit code matches the report).

### Local fixtures/reports and redaction
Fixtures and reports stay on disk by default (`save_fixture` / `load_fixture` / `save_report` / `load_report`, under `fixtures/` and `reports/` via `local_fixture_path` / `local_report_path`). `load_report` accepts both pydantic session dumps and CLI `write_report(..., fmt="json")` output. `RedactionOptions` / `redact_report` / `redact_text` / `redact_mapping` strip secrets before writing or sharing. CLI: `breachguard run --redact`.

### Demo agent for local runs without a live LLM
`VulnerableDemoRunner` follows tool-use hints in prompts so CLI `run` can demonstrate interception without wiring a real agent. Production users supply their own `AgentRunner`.

## Pages

BreachGuard has **no web frontend and no browser routes**. It is a Python package and CLI.

Brand assets shipped with the repo (not a UI):

| Path | What it is |
| --- | --- |
| `frontend/public/logo.svg` | Product logo (primary `#003C30`, accent `#00BFAE`) |
| `frontend/public/favicon.svg` | Favicon variant of the logo |

## API

BreachGuard has **no HTTP backend**. The public surface is the typed Python package (`import breachguard`) and the `breachguard` console script.

### CLI commands

| Command | Purpose |
| --- | --- |
| `breachguard version` | Print package version and configured `PYPI_PACKAGE_NAME` |
| `breachguard init-fixtures [--path] [--force]` | Write a local demo fixture (tools, policy, hand-authored case) |
| `breachguard validate-fixture --fixture PATH` | Validate fixture JSON structure |
| `breachguard generate --fixture PATH --output PATH` | Seeded or LLM-backed case generation (`--llm`, `--api-key`, `--model`, `--base-url`, `--temperature`, `--seed`, `--limit`, `--per-kind`, `--kind`) |
| `breachguard run --fixture PATH` | Run cases with interception; report formats; optional pytest export (`--format`, `--output`, `--export-pytest`, `--redact`, `--tag`, `--case-id`, `--kind`, `--session-id`, `--execute-tools`) |

Also: `python -m breachguard` (same entrypoint).

### Python API (grouped by feature)

**Definitions:** `define_tool`, `define_policy`, `define_fixture`, `deny_tool`, `deny_argument_substring`, `deny_sequence`, `ToolSchema`, `ToolParameter`, `Policy`, `PolicyRule`, `PolicyAction`, `FixtureBundle`

**Generation:** `AttackGenerator`, `AttackGenerationConfig`, `AttackCase`, `AttackKind`, `INJECTION_KINDS`, `hand_authored_case`, `CaseSet`, `LLMClient`, `LLMConfig`, `LLMError`

**Runners:** `AgentRunner`, `CallableRunner`, `DictMessageRunner`, `AttributeAgentRunner`, `OpenAIToolsRunner`, `ScriptedRunner`, `VulnerableDemoRunner`, `as_runner`, `bind_schemas`, `coerce_agent_output`

**Interception & policy:** `Interceptor`, `InterceptResult`, `ToolCall`, `PolicyViolation`, `evaluate_call`, `evaluate_sequence`, `evaluate_policy`, `is_blocking`, `rule_by_id`

**Sessions:** `TestSession`, `SessionOptions`, `SessionReport`, `CaseResult`, `filter_cases`

**Reports:** `ReportFormat`, `write_report`, `render_terminal`, `render_json`, `render_html`, `reproduction_commands`

**Export & CI:** `findings_to_pytest`, `write_pytest_export`, `PytestExportOptions`, `ci_exit_code`

**Local storage & redaction:** `save_fixture`, `load_fixture`, `save_report`, `load_report`, `local_fixture_path`, `local_report_path`, `default_demo_fixture`, `DEFAULT_FIXTURE_DIR`, `DEFAULT_REPORT_DIR`, `RedactionOptions`, `redact_report`, `redact_text`, `redact_mapping`

Minimal library usage:

```python
from breachguard import (
    AttackGenerator,
    Policy,
    PolicyRule,
    ScriptedRunner,
    TestSession,
    ToolSchema,
    write_report,
)

tools = [ToolSchema(name="send_email")]
policy = Policy(name="p", rules=[PolicyRule(id="deny-email", tool_name="send_email")])
cases = AttackGenerator(tools, policy, seed=1).generate(limit=3)
report = TestSession(
    tools=tools,
    policy=policy,
    runner=ScriptedRunner(scripted_calls=[("send_email", {"to": "a@b.c", "body": "x"})]),
).run(cases)
print(write_report(report, fmt="terminal"))
raise SystemExit(report.exit_code)
```

## Configuration

| Name | Required | Purpose |
| --- | --- | --- |
| `PYPI_PACKAGE_NAME` | Yes (for sessions/reports that call `load_settings`) | Provisioned PyPI distribution name, read at runtime for report metadata and `breachguard version` |

Names only are listed in `.env.example`. Do not commit a `.env` file or hardcode values.

### Third-party credentials (caller-supplied)

| Credential | Feature | Where to get it |
| --- | --- | --- |
| OpenAI-compatible API key | LLM-backed attack generation (`AttackGenerator.with_llm`, CLI `generate --llm --api-key`) | Your LLM provider (e.g. OpenAI API keys dashboard, or any compatible host via `--base-url`) |

BreachGuard never bundles or stores a provider key. Pass it per call / CLI invocation. Optional LLM settings: `--model`, `--base-url`, `--temperature`.

## Run it locally

```bash
# Install
uv sync

# Optional: package name used in reports / version output
export PYPI_PACKAGE_NAME=breachguard

# Smoke the CLI
uv run breachguard init-fixtures --path fixtures/demo.json --force
uv run breachguard generate --fixture fixtures/demo.json --output fixtures/cases.json --limit 4
uv run breachguard run --fixture fixtures/cases.json --format terminal

# Tests
uv run pytest

# Lint / typecheck / build (wheel + sdist under dist/)
uv run ruff check .
uv run mypy src
uv build
```

## Architecture

**Stack:** Python package only — no web frontend framework, no HTTP API server, no database, no vector database. Runtime dependencies: Pydantic, Typer, Rich, httpx. Tooling: uv, ruff, mypy, pytest. Distribution name on PyPI: `breachguard` (import package `breachguard`).

**Repository layout**

| Path | Role |
| --- | --- |
| `src/breachguard/` | Library + CLI (`cli.py`, models, generator, interceptor, session, reporters, export, …) |
| `src/breachguard/reporters/` | Terminal / JSON / HTML report renderers |
| `tests/` | Unit tests and doctest runner |
| `frontend/public/` | Brand SVG logo and favicon only |
| `pyproject.toml` | Package metadata, scripts, ruff/mypy/pytest config |
| `.env.example` | Environment variable names |
| `AGENTS.md` | Factory product contract (kept as generated) |

**How “frontend” and “backend” talk:** they do not. There is no browser app and no `/api` server. Users import `breachguard` from Python or invoke the `breachguard` CLI; optional LLM calls go outbound over HTTPS to the caller’s configured OpenAI-compatible endpoint using the caller’s key.
