Metadata-Version: 2.4
Name: techreg-parser
Version: 0.1.1
Summary: Multi-agent system for extracting requirements from data privacy and tech regulation statutes
Author: rafal-fryc
License-Expression: MIT
Project-URL: Homepage, https://github.com/rafal-fryc/TechRegParser
Project-URL: Documentation, https://github.com/rafal-fryc/TechRegParser#readme
Project-URL: Repository, https://github.com/rafal-fryc/TechRegParser
Keywords: statute,legal,privacy,compliance,ai,agent,tech-regulation
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Legal Industry
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Text Processing :: General
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: claude-agent-sdk>=0.1.0
Requires-Dist: pydantic>=2.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: isort>=5.12.0; extra == "dev"
Requires-Dist: mypy>=1.0.0; extra == "dev"
Provides-Extra: pdf
Requires-Dist: pypdf>=3.0.0; extra == "pdf"
Requires-Dist: pdfplumber>=0.9.0; extra == "pdf"
Dynamic: license-file

# TechRegParser

A multi-agent system for extracting requirements from data privacy and tech regulation statutes using the Anthropic Agent SDK.

## Features

- **Multi-agent architecture**: Specialized agents for different tasks:
  - **Statute Reader**: Parses statute structure (definitions, applicability, rights, duties, exemptions, enforcement)
  - **Section Analyzer**: Extracts specific requirements with exact citations
  - **Citation Verifier**: Validates all citations against the original text
  - **Requirement Classifier**: Categorizes requirements (disclosure, operational, technical, enforcement)

- **Model Configuration**:
  - **Orchestrator**: Uses Opus for complex coordination
  - **Subagents**: Use Sonnet for specialized tasks

- **Anti-hallucination measures**:
  - Every requirement must have a direct quote from the statute
  - Two-pass verification (extract then verify)
  - Confidence scoring for citations
  - Flagging of unverified requirements

- **Diagnostics and logging**:
  - Phase 1 logs section/definition counts on success, or a clear warning on failure
  - Parse failures log the raw agent response details for debugging

- **Statute interpretation skill**: Incorporates statutory interpretation guidance from legal experts

- **PDF Support**: Can parse both text files and PDFs (with pdfplumber or pypdf)

## Installation

```bash
# Install from PyPI
pip install techreg-parser

# With PDF support
pip install techreg-parser[pdf]

# Or install locally for development
pip install -e .
```

## Usage

### Command Line

```bash
# Analyze a statute and output JSON
techreg-parser path/to/statute.txt --output results.json

# Analyze a PDF statute
techreg-parser path/to/statute.pdf --output results.json

# Output markdown report
techreg-parser path/to/statute.txt --output analysis.md --format markdown

# Skip citation verification (faster but less reliable)
techreg-parser path/to/statute.txt --no-verify
```

### Python API

```python
import asyncio
from TechRegParser import TechRegParserOrchestrator, OrchestratorConfig

async def main():
    config = OrchestratorConfig(
        verify_citations=True,
        classify_requirements=True,
    )

    parser = TechRegParserOrchestrator(config=config)

    result = await parser.analyze_statute(
        statute_path="path/to/texas_privacy_law.txt",
        output_format="json"
    )

    # Access results
    for req in result.requirements:
        print(f"Requirement: {req.description}")
        print(f"  Citation: {req.citation.section}")
        print(f"  Category: {req.category.value}")
        print(f"  Verified: {req.verified}")
        print()

    # Export to file
    await parser.export_results(result, "output.json", format="json")

asyncio.run(main())
```

## Architecture

```
                    +-------------------+
                    |   Orchestrator    |
                    |   (Opus Model)    |
                    +--------+----------+
                             |
        +--------------------+--------------------+
        |           |              |              |
+-------v----+ +----v-----+ +-----v------+ +-----v------+
|  Statute   | | Section  | | Citation   | |Requirement |
|  Reader    | | Analyzer | | Verifier   | | Classifier |
| (Sonnet)   | | (Sonnet) | | (Python)   | | (Sonnet)   |
+------------+ +----------+ +------------+ +------------+
```

## Requirement Categories

- **DISCLOSURE**: Must be stated in privacy policy/notice
- **OPERATIONAL**: Internal compliance processes (response times, procedures)
- **TECHNICAL**: System/UI implementation (GPC signals, security measures, link placement, UI elements)
- **LEGAL FRAMEWORK**: Enforcement mechanisms, penalties, AG authority, cure periods

## Output

The analysis produces:
- **Requirements**: List of all extracted requirements with citations
- **Definitions**: All defined terms from the statute
- **Structure**: Full statute section tree (IDs, types, titles, line ranges) — included by default in JSON export for the viewer's Structure tab
- **Verification**: Status of citation verification
- **Classification**: Category for each requirement

## Key Principles

Based on lessons from analyzing tech regulation statutes:

1. Start with definitions sections to anchor interpretation — defined terms control meaning throughout
2. Separate disclosure requirements from operational and technical requirements
3. Tech regulation statutes follow predictable architecture (definitions, scope, rights, duties, exemptions, enforcement)
4. Obligations and defined terms vary across jurisdictions and regulatory domains — never assume uniformity
5. Work section by section, not requirement by requirement — structure drives accurate extraction
6. Every extracted requirement must trace back to a specific statutory provision with a verbatim quote

## Requirements

- Python 3.11+
- Anthropic Agent SDK (`claude-agent-sdk`)
- Pydantic 2.0+
- Optional: pdfplumber or pypdf for PDF support

## License

MIT
