Metadata-Version: 2.4
Name: qwed-legal
Version: 0.1.0
Summary: 🏛️ Verification guards for legal contracts - Date calculations, clause consistency, liability verification
Project-URL: Homepage, https://github.com/QWED-AI/qwed-legal
Project-URL: Documentation, https://docs.qwedai.com/legal
Project-URL: Repository, https://github.com/QWED-AI/qwed-legal
Project-URL: Issues, https://github.com/QWED-AI/qwed-legal/issues
Author-email: Rahul Dass <rahul@qwedai.com>
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: ai,compliance,contracts,hallucination,law,legal,llm,verification
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Legal Industry
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Office/Business
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Requires-Dist: holidays>=0.40
Requires-Dist: python-dateutil>=2.8.0
Requires-Dist: sympy>=1.12
Requires-Dist: z3-solver>=4.12.0
Provides-Extra: dev
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Description-Content-Type: text/markdown

<div align="center">
  <h1>🏛️ QWED-Legal</h1>
  <h3>Verification Guards for Legal Contracts</h3>
  
  > **Catch AI hallucinations before they become lawsuits.**
  
  <p>
    <b>Don't trust AI with legal analysis. Verify it.</b><br>
    <i>Deadline math • Clause contradictions • Liability calculations</i>
  </p>

  [![PyPI version](https://img.shields.io/pypi/v/qwed-legal)](https://pypi.org/project/qwed-legal/)
  [![Tests](https://github.com/QWED-AI/qwed-legal/actions/workflows/ci.yml/badge.svg)](https://github.com/QWED-AI/qwed-legal/actions)
  [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

</div>

---

## 🚨 The Problem

**Lawyers are using AI to review contracts. AI makes mistakes.**

| Case | What Happened | Impact |
|------|--------------|--------|
| **Mata v. Avianca (2023)** | ChatGPT cited 6 fake legal cases | $5,000 fine, sanctions |
| **Contract Review Errors** | LLMs miss contradictory clauses | Disputes, litigation |
| **Date Calculation Bugs** | "30 business days" miscalculated | Missed deadlines, defaults |

---

## ⚡ Quick Start

### Installation

```bash
pip install qwed-legal
```

### Verify a Deadline Calculation

```python
from qwed_legal import DeadlineGuard

guard = DeadlineGuard()
result = guard.verify(
    signing_date="2026-01-15",
    term="30 business days",
    claimed_deadline="2026-02-14"  # LLM claimed this
)

print(result.verified)   # False!
print(result.computed_deadline)  # 2026-02-27 (correct)
print(result.message)
# ❌ ERROR: Deadline mismatch. Expected 2026-02-27, but LLM claimed 2026-02-14.
```

### Verify a Liability Cap

```python
from qwed_legal import LiabilityGuard

guard = LiabilityGuard()
result = guard.verify_cap(
    contract_value=5_000_000,
    cap_percentage=200,
    claimed_cap=15_000_000  # LLM said 15M
)

print(result.verified)  # False!
print(result.computed_cap)  # 10,000,000 (200% of 5M)
# ❌ ERROR: 200% of $5M = $10M, not $15M
```

### Detect Contradictory Clauses

```python
from qwed_legal import ClauseGuard

guard = ClauseGuard()
result = guard.check_consistency([
    "Seller may terminate with 30 days notice",
    "Neither party may terminate before 90 days",
    "Seller may terminate immediately upon breach"
])

print(result.consistent)  # False!
# ⚠️ WARNING: Clauses 1 and 2 may conflict (days 30-90)
```

---

## 🛡️ The Four Guards

| Guard | What It Verifies |
|-------|------------------|
| **DeadlineGuard** | Date calculations, business days, leap years |
| **LiabilityGuard** | Cap percentages, tiered liability, indemnity limits |
| **ClauseGuard** | Clause contradictions, termination conflicts |
| **CitationGuard** | Legal citations (Bluebook format, case names, reporters) |

### Verify Legal Citations (New!)

```python
from qwed_legal import CitationGuard

guard = CitationGuard()
result = guard.verify("Brown v. Board of Education, 347 U.S. 483 (1954)")

print(result.valid)  # True
print(result.parsed_components)
# {'plaintiff': 'Brown', 'defendant': 'Board of Education', 'volume': 347, 'reporter': 'U.S.', 'page': 483, 'year': 1954}
```

---

## 📊 Audit Log: Real Hallucinations Caught

| Contract Input | LLM Claim | QWED Verdict |
|----------------|-----------|--------------|
| "Net 30 Business Days from Dec 20" | Jan 19 | 🛑 **BLOCKED** (Actual: Feb 2, 2026) |
| "Liability Cap: 2x Fees ($50k)" | $200,000 | 🛑 **BLOCKED** (Actual: $100,000) |
| "Seller may terminate with 30 days notice" + "Neither party may terminate before 90 days" | "Clauses are consistent" | 🛑 **BLOCKED** (Conflict detected) |
| "Smith v. Jones, 999 FAKE 123" | Valid citation | 🛑 **BLOCKED** (Unknown reporter) |

---

## 🏦 All-in-One Guard

```python
from qwed_legal import LegalGuard

guard = LegalGuard()

# All verification methods in one object
guard.verify_deadline(...)
guard.verify_liability_cap(...)
guard.check_clause_consistency(...)
```

---

## 🌍 Jurisdiction Support

DeadlineGuard supports jurisdiction-specific holidays:

```python
from qwed_legal import DeadlineGuard

# US holidays (default)
us_guard = DeadlineGuard(country="US")

# UK holidays
uk_guard = DeadlineGuard(country="GB")

# California-specific holidays
ca_guard = DeadlineGuard(country="US", state="CA")
```

---

## 🔗 Related QWED Packages

| Package | Purpose |
|---------|---------|
| [qwed-verification](https://github.com/QWED-AI/qwed-verification) | Core verification engine |
| [qwed-finance](https://github.com/QWED-AI/qwed-finance) | Banking & financial verification |
| [qwed-ucp](https://github.com/QWED-AI/qwed-ucp) | E-commerce transaction verification |
| [qwed-mcp](https://github.com/QWED-AI/qwed-mcp) | Claude Desktop integration |

---

## 📄 License

Apache 2.0 - See [LICENSE](LICENSE)

---

<div align="center">
  <b>⭐ Star us if you believe AI needs verification in legal domains</b>
  <br><br>
  <i>"In law, precision isn't optional. QWED makes it verifiable."</i>
</div>
