Metadata-Version: 2.4
Name: llmfw
Version: 0.1.0
Summary: A safety layer between your application and any LLM API — input/output firewalling, PII redaction, jailbreak detection, and domain-specific guardrails.
Author: llmfw contributors
License: MIT
Project-URL: Homepage, https://github.com/navyavelicheti10/LLM_Firewall
Project-URL: Documentation, https://llmfw.readthedocs.io
Project-URL: Repository, https://github.com/navyavelicheti10/LLM_Firewall
Project-URL: Issues, https://github.com/navyavelicheti10/LLM_Firewall/issues
Keywords: llm,security,firewall,prompt-injection,guardrails,ai-safety
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Security
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyyaml>=6.0
Provides-Extra: dashboard
Requires-Dist: fastapi>=0.110; extra == "dashboard"
Requires-Dist: uvicorn>=0.29; extra == "dashboard"
Provides-Extra: finance
Provides-Extra: medical
Provides-Extra: legal
Provides-Extra: all
Requires-Dist: fastapi>=0.110; extra == "all"
Requires-Dist: uvicorn>=0.29; extra == "all"
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: httpx>=0.27; extra == "dev"
Provides-Extra: docs
Requires-Dist: mkdocs-material>=9.5; extra == "docs"
Dynamic: license-file

# llmfw — LLM Firewall

A safety layer between your application and any LLM API. It inspects prompts
(input) and responses (output), applies a set of default checks, and
optionally applies extra domain-specific checks (finance, medical, legal,
...). Ships with a local dashboard to visualize what got flagged or blocked
over time.

## Install

```bash
pip install llmfw            # core
pip install llmfw[dashboard] # + local dashboard (FastAPI/uvicorn)
pip install llmfw[all]       # everything
```

## Quickstart

```python
from llmfw import Firewall

fw = Firewall(domain="finance")

result = fw.check_input(user_prompt)
if not result.allowed:
    return "Request blocked: " + result.blocked_by

response = call_llm(result.redacted_text)

out_result = fw.check_output(response)
if not out_result.allowed:
    return "Response blocked"

return out_result.redacted_text
```

Or wrap the whole request/response cycle in one call:

```python
result = fw.protect(user_prompt, llm_call_fn=call_llm)
```

See [examples/quickstart.py](examples/quickstart.py) for a runnable version.

## What it checks

**Default detectors** (always run):

- **Injection** — prompt injection / jailbreak detection (pattern, structural, and paraphrase matching)
- **PII** — emails, phone numbers, SSNs, card numbers (Luhn-validated), IPs — redacted in place
- **Output validator** — schema/length checks, basic hallucination markers
- **Leak guard** — detects system-prompt-like content leaking into output
- **Multi-turn tracker** — flags cumulative suspicious patterns across a session
- **Toxicity** — hate speech / self-harm / abuse filter
- **Obfuscation** — decodes base64/unicode/leetspeak tricks before re-running the other checks

**Domain packs** (opt-in via `domain=`):

- **finance** — guaranteed-return scam phrasing, unlicensed investment advice, pump-and-dump/fake-ticker hype
- **medical** — unlicensed diagnosis/prescription language, unsafe dosage mentions, patient-identifiable health info (PHI)
- **legal** — unauthorized legal advice/guaranteed-outcome phrasing, unverified case citations flagged for human review

## CLI

```bash
llmfw check "some prompt" --domain finance
llmfw dashboard              # launch the local dashboard at localhost:8420
llmfw test --domain finance  # run the curated attack-prompt suite
```

## Dashboard

`llmfw dashboard` starts a local FastAPI server (requires the `dashboard`
extra) that serves a small UI showing recent blocked/flagged events, a
breakdown by rule and domain, and a blocks-per-day trend. Events are logged to
a local SQLite database (`llmfw_events.db` by default).

## Configuration

```yaml
# llmfw.config.yaml
domain: finance
enabled_detectors:
  - injection
  - pii
  - output_validator
  - leak_guard
  - multiturn_tracker
  - toxicity
  - obfuscation
thresholds:
  injection: 0.6
log_events: true
db_path: llmfw_events.db
```

```python
fw = Firewall(config="llmfw.config.yaml")
```

## Testing

```bash
pip install -e ".[dev,dashboard]"
pytest tests/
python -m tests.benchmark   # false-positive / false-negative rate per domain
```

## License

MIT
