Skip to content

noamrazbuilds/legal-comms-engine

Repository files navigation

Legal Communications Template Engine

Generate common legal communications from templates with intelligent variable insertion. Supports 7 communication types with a web interface, API, and optional AI-powered text enhancement.

Communication types: Breach/Cure Notices, Privacy Incident Notifications, Contract Award/Rejection Letters, Vendor Termination Letters, Legal Hold Notices, Regulatory Inquiry Responses, Board/Executive Legal Updates.


Quick Start

Option 1: Run locally (recommended)

git clone https://github.com/lquantprojects/legal-comms-engine.git
cd legal-comms-engine
./start.sh          # macOS/Linux
start.bat           # Windows

This installs dependencies, starts the API and frontend, and opens your browser.

Option 2: Docker

docker compose up

Option 3: Manual setup

python3 -m venv .venv
source .venv/bin/activate       # macOS/Linux
pip install -e .
python scripts/create_templates.py

# Terminal 1: Start API
uvicorn api.main:app --reload --port 8000

# Terminal 2: Start frontend
streamlit run lce_lce_frontend/app.py --server.port 8501

Features

  • 7 communication types with structured input forms and Word (.docx) output
  • Template-driven: .docx templates with Jinja2 placeholders — easy to customize
  • Communication log with search, filter, and status tracking (draft/sent/final)
  • AI enhancement (optional): Bring your own Anthropic API key to refine tone and adapt for jurisdiction
  • API-first: Full REST API with Swagger docs — usable from curl, scripts, or integrations
  • Extensible: Add a new communication type in 3 steps (schema + registry entry + template file)

AI Enhancement (Optional)

To enable Claude-powered text enhancement:

  1. Go to Settings in the sidebar
  2. Enter your Anthropic API key (starts with sk-ant-)
  3. When generating a communication, check "Enhance with Claude"
  4. Choose a tone (formal, firm, conciliatory, neutral, urgent) and/or jurisdiction
  5. Review the enhanced text before generating

Your API key is stored only in your browser session and is never saved to disk.


API Reference

The API is documented at http://localhost:8000/docs (Swagger UI).

Key endpoints:

Method Endpoint Description
GET /templates List available communication types
GET /templates/{type}/schema Get JSON Schema for a type's fields
POST /communications/generate Generate a communication
GET /communications/{id}/download Download generated .docx
GET /communications List/search/filter communication log
PATCH /communications/{id}/status Update status (draft/sent/final)
POST /claude/enhance Enhance text with Claude (requires API key header)

Example: Generate via curl

curl -X POST http://localhost:8000/communications/generate \
  -H "Content-Type: application/json" \
  -d '{
    "communication_type": "breach_cure_notice",
    "fields": {
      "counterparty": "Acme Corp",
      "breach_description": "Failure to deliver under Section 4.2",
      "cure_period": "30 days",
      "remediation_steps": ["Deliver outstanding items", "Provide status report"]
    },
    "author": "Jane Smith"
  }'

Project Structure

api/                  FastAPI backend
  routers/            API endpoints
  schemas/            Pydantic models (including communication type registry)
  services/           Business logic (generator, template engine, Claude service)
  models/             SQLAlchemy ORM models
lce_frontend/             Streamlit web interface
  pages/              Generate, Log, Settings pages
templates/            .docx template files with Jinja2 placeholders
data/sample/          Synthetic example data
tests/                pytest test suite

Adding a New Communication Type

  1. Add a Pydantic schema class in api/schemas/communication_types.py
  2. Add a registry entry in COMMUNICATION_TYPE_REGISTRY in the same file
  3. Create a .docx template file in templates/ with matching placeholders

No router, frontend, or database changes required.


Tech Stack

  • Backend: Python 3.11+, FastAPI, SQLAlchemy, Pydantic v2
  • Document generation: docxtpl (Jinja2 templates in Word)
  • Frontend: Streamlit
  • Database: SQLite (designed for PostgreSQL migration)
  • AI: Anthropic API (Claude) — optional, BYOK
  • Deployment: Docker, Railway

License

MIT

About

Template engine that generates common legal communications (breach notices, privacy notifications, vendor termination letters, legal holds, and more) from structured inputs with optional Claude AI enhancement for tone and jurisdiction customization.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors