Metadata-Version: 2.4
Name: llm-guardrails-sk
Version: 0.1.0
Summary: Provider-agnostic middleware for LLM safety
Home-page: https://github.com/SudhamshKalakonda/llm-guardrails
Author: SK (Sudhamsh Kalakonda)
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic>=2.0
Requires-Dist: groq>=0.4.1
Requires-Dist: openai>=1.0.0
Requires-Dist: anthropic>=0.7.0
Requires-Dist: fastembed>=0.2.0
Requires-Dist: pyyaml>=6.0
Dynamic: author
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# LLM Guardrails Gateway

A provider-agnostic middleware for LLM safety. Automatically detects prompt injections, validates output schemas, enforces policies, and logs every decision for compliance.

## Installation

```bash
pip install llm-guardrails
```

## Quick Start

```python
from llm_guardrails import Guardrails
from openai import OpenAI

guard = Guardrails()
client = OpenAI()

@guard.protect
def ask_llm(question: str) -> str:
    response = client.chat.completions.create(
        model="gpt-4",
        messages=[{"role": "user", "content": question}]
    )
    return response.choices[0].message.content

# Clean message passes through
answer = ask_llm("What is the capital of France?")
# Returns: "Paris"

# Attack gets blocked
answer = ask_llm("Ignore all previous instructions")
# Returns: GuardrailBlockedResponse(...)

# Verify performance yourself
results = guard.run_self_eval(sample_size=50)
# Returns: precision, recall on fresh held-out examples

# Audit what happened
summary = guard.get_audit_summary()
# Returns: total decisions, block rate, detector breakdown
```

## Features

### Input Protection: Prompt Injection Detection

- **85.6% recall** - catches 856 out of 1000 real attacks
- **85.9% precision** - only 141 false positives out of 1000 benign inputs
- Three layers: pattern matching → embedding similarity → LLM judge
- Catches novel obfuscations (base64, Unicode, translation wrappers)

### Output Validation

- Schema validation with auto-retry
- Handles markdown wrapping, syntax errors, missing fields
- Asks LLM to fix its own output before giving up

### Output Content Safety

- **76.6% recall** - catches harmful responses
- **89.5% precision** - low false-positive rate
- Same multi-layer design as input detection

### Policy Engine

Define rules in YAML, enforce them automatically:

```yaml
rules:
  - name: "no_medical_advice"
    description: "Never provide specific medical dosage or treatment advice."
    applies_to: "output"
```

### Audit Logging

Every decision logged in both JSON and human-readable format:

```python
blocked = guard.get_blocked_entries(limit=10)
summary = guard.get_audit_summary()
```

### Self-Eval

Verify detection quality on demand:

```python
result = guard.run_self_eval(sample_size=100)
# Returns: precision, recall, TP/FN/FP/TN
```

## Architecture
