Metadata-Version: 2.4
Name: llmfw
Version: 0.1.1
Summary: LLM Firewall: 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 firewall,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

# LLM Firewall (`llmfw`)

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
```

## What to do after installing

You already have a chatbot or an app that calls an LLM. There are exactly
**3 things to add** around your existing code — nothing else changes.

```python
from llmfw import Firewall

fw = Firewall(domain="finance")  # 1. create once (pick your domain, or omit it)

def handle_message(user_message):
    check = fw.check_input(user_message)          # 2. check what the user sent
    if not check.allowed:
        return f"Sorry, I can't help with that ({check.blocked_by})."

    response = call_your_llm(check.redacted_text)  # your existing LLM call, unchanged

    out_check = fw.check_output(response)          # 3. check what the LLM sent back
    if not out_check.allowed:
        return "Sorry, I can't share that response."

    return out_check.redacted_text
```

Replace `call_your_llm(...)` with whatever you already use (OpenAI, Claude,
Gemini, ...) — that part doesn't change. `fw` should be created **once per
user session**, not once globally for your whole app (see
[docs/architecture.md](https://llmfw.readthedocs.io/en/latest/architecture/#sessions-and-multi-turn-state)
for why).

Prefer one line instead of wrapping input/output separately?

```python
result = fw.protect(user_message, llm_call_fn=call_your_llm)
if not result.allowed:
    return f"Blocked: {result.blocked_by}"
return result.redacted_text
```

See [examples/quickstart.py](examples/quickstart.py) for a runnable version,
or the [full docs](https://llmfw.readthedocs.io) for configuration, the CLI,
and the dashboard.

## 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
