Contract Review System is a Retrieval-Augmented Generation (RAG)-based legal document analysis platform designed to automate contract understanding, compliance checking, clause summarization, and risk assessment.
The project was developed as part of my major project focusing on explainable and modular AI-assisted contract analysis.
- Extracts key contract sections
- Generates concise clause summaries
- Uses retrieval-based contextual summarization
- Rule-based compliance evaluation
- Semantic retrieval using FAISS
- Multi-stage keyword validation pipeline
- Evidence-based clause extraction
-
Business risk assessment based on compliance results
-
Generates:
- Risk level
- Business impact
- Recommendations
-
Generates structured downloadable PDF reports
-
Includes:
- Clause summaries
- Compliance results
- Risk analysis
The system follows a Retrieval-Augmented Generation (RAG) architecture:
- PDF text extraction
- Chunk creation with overlap
- Embedding generation using MiniLM
- Vector storage in FAISS
- Semantic retrieval using rule-based queries
- LLM-based analysis on retrieved chunks
Rule Selection
↓
Query Generation
↓
FAISS Retrieval
↓
Keyword Validation
↓
LLM Clause Extraction
↓
Evidence Verification
↓
COMPLIANT / NON-COMPLIANT
The compliance system uses a hybrid retrieval-validation approach combining semantic retrieval with strict keyword-based verification.
| Component | Technology |
|---|---|
| Frontend | Streamlit |
| LLM | Fine-Tuned Mistral 7B |
| Embeddings | all-MiniLM-L6-v2 |
| Vector Database | FAISS |
| PDF Processing | PyMuPDF |
| Report Generation | ReportLab |
| Inference Hosting | Google Colab + Ngrok |
| Training Framework | Hugging Face + LoRA/QLoRA |
Contract-Review-System/
│
├── app.py
├── requirements.txt
├── README.md
├── LICENSE
├── .gitignore
├── .env.example
│
└── src/
│
├── compliance_checker.py
├── key_clause_summarizer.py
├── llm_client.py
├── pdf_processor.py
├── report_generator.py
├── risk_and_reco.py
└── vector_store.py
The following folders are excluded from the repository:
| Folder | Reason |
|---|---|
models/ |
Large GGUF model files |
data/ |
Generated vector indexes and metadata |
logs/ |
Runtime logs |
config/ |
Environment-specific configuration |
trainingV2/ |
Training datasets and generated training files |
The base Mistral-7B Instruct v0.2 model was fine-tuned for legal contract analysis using LoRA/QLoRA with Unsloth for memory-efficient training. The model was trained on legal-domain instruction datasets to improve contract understanding, summarization, clause interpretation, compliance reasoning, and risk assessment.
- CUAD (Contract Understanding Atticus Dataset)
- ACORD Dataset
- Custom compliance-rule datasets
- Parameter-efficient fine-tuning using LoRA/QLoRA
- LoRA adapters applied to the transformer's attention (
q_proj,k_proj,v_proj,o_proj) and feed-forward (gate_proj,up_proj,down_proj) layers - Tuned key hyperparameters including
LoRA rank,LoRA alpha,learning rate,batch size,gradient accumulation, andmaximum sequence length - 4-bit quantization for memory-efficient training and inference
- Training performed using Supervised Fine-Tuning (SFT) with the Unsloth framework
- Legal clause understanding
- Contract summarization
- Compliance-oriented reasoning
- Risk identification and recommendations
- Question answering over legal contracts
The fine-tuned model was exported to GGUF (Q4_K_M) format for efficient inference using llama.cpp, and later served through FastAPI for integration with the RAG pipeline.
- Hybrid RAG-based legal analysis pipeline
- Rule-driven compliance evaluation
- Multi-stage evidence verification
- Modular explainable architecture
- Integration of retrieval and legal reasoning workflows
- Compliance logic is primarily keyword-guided
- Requires active remote inference server
- Performance depends on retrieval quality
- Does not replace professional legal review
- Full logical compliance reasoning
- Multi-contract comparison
- Clause highlighting in PDFs
- Persistent analysis caching
- Improved legal reasoning datasets
- Multi-agent legal workflows
This project is intended for research and educational purposes only. It does not provide legal advice. It is under MIT License