LawLens is an AI-powered legal research and document analysis system that helps users analyze legal documents, explore case outcomes, and generate structured legal reports.
The system uses Retrieval-Augmented Generation (RAG) to retrieve relevant sections from uploaded PDF documents before sending them to an LLM. This helps keep the generated responses grounded in the content of the provided documents.
Upload one or more legal documents and ask a question about them.
The system:
- Extracts text from uploaded PDFs
- Splits the text into smaller chunks
- Creates vector embeddings
- Stores the embeddings using FAISS
- Retrieves the most relevant document sections
- Generates a legal analysis using an LLM
The response includes:
- Legal Analysis
- Available Options
- Recommendations
- Potential Risks
Analyze a legal document and receive an AI-generated assessment of the possible case outcome.
The system provides:
- Likelihood Assessment
- Key Factors Influencing the Outcome
- Potential Scenarios
- Recommendations for Improving the Chances of a Favorable Outcome
Note: The prediction is an AI-generated assessment based on the provided document and should not be considered a guaranteed legal outcome.
Generate a structured legal report from uploaded documents and a user query.
The generated report contains:
- Executive Summary
- Key Findings
- Legal Analysis
- Recommendations
- Conclusion
LawLens follows a Retrieval-Augmented Generation (RAG) pipeline.
User
│
▼
Upload Legal PDF(s)
│
▼
PDF Text Extraction
(PyPDF2)
│
▼
Text Chunking
(RecursiveCharacterTextSplitter)
│
▼
Generate Embeddings
(all-MiniLM-L6-v2)
│
▼
FAISS Vector DB
│
▼
Similarity Search (Top 6)
│
▼
Relevant Document Sections
│
▼
Groq LLM (GPT-OSS 120B)
│
▼
Generated Legal Response
- Python
- FastAPI
- Uvicorn
- Groq API
- GPT-OSS 120B
- LangChain Groq
- FAISS
- Hugging Face Sentence Transformers
sentence-transformers/all-MiniLM-L6-v2- RecursiveCharacterTextSplitter
- PyPDF2
- FastAPI File Uploads
- CORS Middleware
- Python-dotenv
LawLens/
│
├── backend/
│ ├── main.py
│ ├── .env
│ └── requirements.txt
│
├── frontend/
│ └── ...
│
└── README.md
The exact folder structure may vary depending on your project setup.
git clone https://github.com/Ranjith00005/LawLens.git
cd LawLenspython -m venv venvActivate it:
source venv/bin/activatevenv\Scripts\activatepip install -r requirements.txtIf you haven't created requirements.txt, the main dependencies used by the backend are:
fastapi
uvicorn
langchain-groq
langchain-text-splitters
langchain-community
sentence-transformers
faiss-cpu
PyPDF2
python-dotenv
python-multipart
Create a .env file in the backend directory:
GROQ_API_KEY=your_groq_api_keyReplace your_groq_api_key with your Groq API key.
Do not commit your .env file to GitHub.
Add it to .gitignore:
.env
venv/
__pycache__/
Start the FastAPI server with:
uvicorn main:app --reloadOr run the Python file directly:
python main.pyThe API will be available at:
http://localhost:8000
FastAPI automatically provides interactive API documentation at:
http://localhost:8000/docs
POST /legal-advisory/query— User's legal questionfiles— One or more PDF documents
Query:
"What are the possible legal remedies available to the plaintiff?"
{
"result": "Legal analysis..."
}POST /case-outcome-prediction/query— Case-related questionfiles— Legal PDF documents
{
"prediction": "Likelihood assessment..."
}POST /report-generator/query— Report requirementsfiles— Legal PDF documents
{
"report": "Generated legal report..."
}LawLens uses Retrieval-Augmented Generation instead of directly passing the entire document to the language model.
Uploaded PDFs are processed using PyPDF2.
pdf_reader = PyPDF2.PdfReader(io.BytesIO(content))Text is extracted from each page.
The extracted text is divided into smaller sections.
CHUNK_SIZE = 700
CHUNK_OVERLAP = 150A 150-character overlap helps preserve context between neighboring chunks.
Each text chunk is converted into a vector representation using:
sentence-transformers/all-MiniLM-L6-v2
The embeddings are stored in a FAISS vector database.
vector_db = FAISS.from_texts(chunks, embedding_model)When the user asks a question, LawLens searches the vector database for the most relevant sections.
RETRIEVAL_TOP_K = 6The top six relevant chunks are retrieved.
The retrieved content and user query are provided to the Groq-hosted LLM.
chat = ChatGroq(
model="openai/gpt-oss-120b",
api_key=groq_api_key
)The model then generates the final response based on the retrieved document content.
The main RAG parameters can be adjusted in the backend:
CHUNK_SIZE = 700
CHUNK_OVERLAP = 150
RETRIEVAL_TOP_K = 6Controls the amount of text contained in each document chunk.
Maintains some repeated context between neighboring chunks.
Controls how many relevant chunks are passed to the LLM.
LawLens handles several document-processing issues, including:
- Empty user queries
- PDFs with no extractable text
- Image-based PDFs
- AI processing errors
For example, if a PDF contains no extractable text, the API returns an error indicating that OCR or a text-based PDF may be required.
For production deployment, additional security measures should be implemented.
Recommended improvements include:
- Restricting CORS origins
- Validating uploaded file types
- Limiting PDF file sizes
- Adding authentication and authorization
- Protecting API keys
- Adding rate limiting
- Sanitizing user input
- Using secure production deployment settings
Potential future enhancements include:
- OCR support for scanned legal documents
- Persistent vector database storage
- Citation and source highlighting
- Legal case-law database integration
- Multi-document comparison
- Document summarization
- User authentication
- Conversation history
- Improved legal-domain prompting
- Cloud deployment
- Streaming AI responses
LawLens is an AI-assisted legal research and document analysis tool.
It is intended for educational and research purposes and does not replace advice from a qualified legal professional. AI-generated analysis and predictions may contain errors and should be independently verified.
Ranjith Rameshbabu
GitHub: https://github.com/Ranjith00005/LawLens
- AI-powered legal document analysis
- Retrieval-Augmented Generation (RAG)
- Semantic document search
- FAISS vector similarity search
- Hugging Face embeddings
- Groq LLM integration
- REST API using FastAPI
- Multi-PDF document processing
- Automated legal report generation
- Case outcome assessment