A legal compliance analysis tool that automatically checks Terms of Service and Privacy Policy documents against Indian IT laws and regulations using RAG (Retrieval-Augmented Generation).
AttorneysInRAGs analyzes legal documents through a multi-stage pipeline:
- Filtering - Extracts relevant legal clauses using ontology-based keyword matching + AI classification
- Matching - Embeds clauses and queries a vector database of laws to find potential matches
- Analysis - Uses an LLM to determine if matches constitute actual violations
┌─────────────┐ ┌──────────────┐ ┌─────────────┐ ┌──────────────┐
│ Input ToS │───▶│ Filter │───▶│ Vector DB │───▶│ LLM │
│ Document │ │ (filter.py) │ │ (matcher) │ │ (inference) │
└─────────────┘ └──────────────┘ └─────────────┘ └──────────────┘
│ │ │
Ontology + AI ChromaDB + Ollama +
Classification BGE Embeddings Mistral
- Python 3.11 or 3.12.3 (<3.14)
- Ollama with
mistral:latestmodel
# Clone and enter directory
cd AttorneysInRAGs
# Create virtual environment
python -m venv venv
source venv/bin/activate
# Install dependencies
pip install chromadb sentence-transformers spacy transformers fastapi uvicorn httpx
# Download spaCy model
python -m spacy download en_core_web_sm
# Pull Ollama model
ollama pull mistral:latestpython experimentation/db_generator.pyThis populates the ChromaDB vector database with embedded law rationales from backend/database/db.json.
python backend/main.pyReads backend/text.txt and runs the full pipeline.
# From project root
uvicorn backend.api:app --host 0.0.0.0 --port 8000POST /analyze
curl -X POST http://localhost:8000/analyze \
-H "Content-Type: application/json" \
-d '{"text": "Your Terms of Service text here..."}'{
"summary": "Executive summary of violations found.",
"aggregations": {
"total_violations": 2,
"critical_severity": 1,
"high_severity": 1,
"medium_severity": 0,
"low_severity": 0
},
"violations": [
{
"violating_rule": "ToS clause text...",
"actual_rule": "The actual law text...",
"source": "[IT_ACT_SEC_43A] DATA_SHARING, LIABILITY",
"severity": "CRITICAL",
"reason": "Why this is a violation"
}
...
]
}AttorneysInRAGs/
├── backend/
│ ├── api.py # FastAPI server
│ ├── main.py # CLI pipeline runner
│ ├── filter.py # RelevanceFilter (ontology + AI)
│ ├── matcher.py # Vector search + matching
│ ├── inference.py # LLM inference (Ollama)
│ ├── text.txt # Sample input for testing
│ └── database/
│ ├── db.json # Law rules database
│ └── chroma_db/ # Vector embeddings
├── experimentation/
│ ├── db_generator.py # Populate ChromaDB
│ └── svo.py # Text distillation experiments
└── README.md
Uses BAAI/bge-small-en-v1.5 (384-dim) for fast, high-quality embeddings.
Default: Ollama with mistral:latest. Configure in backend/inference.py:
OLLAMA_URL = "http://localhost:11434/api/generate"
MODEL = "mistral:latest"Adjust in backend/matcher.py:
threshold=0.40 # Lower = stricter matchingDATA_COLLECTION- Data gathering practicesDATA_RETENTION- Storage duration requirementsDATA_SHARING- Third-party sharing rulesCONSENT- User consent requirementsSECURITY_PRACTICES- Security standardsBREACH_RESPONSE- Incident notification rulesUSER_RIGHTS- Access, correction, deletion rightsGRIEVANCE- Complaint handling proceduresLIABILITY- Liability and indemnificationSENSITIVE_DATA- Special category data rulesCHILDREN_DATA- Minor protection rulesLOGGING_AUDIT- Audit trail requirements
IT Act, 2000 Sections 43 & 66
DPDP Act, 2023
IT Security Practices Rules
CERT-In Guidelines
IT Intermediary Guidelines
MIT