AI Legal Analysis

LegisFlow

AI agent for automated legal document analysis — upload PDF contracts and get instant structured risk reports with compliance recommendations.
n8n OpenAI GPT-4o Telegram Bot PDF Processing 2026

Context & Problem

Business Case

Legal document review is time-consuming, expensive, and requires specialized expertise. Small businesses and individuals often sign contracts without proper analysis due to high legal fees, exposing themselves to hidden risks, unfavorable clauses, and compliance violations.

The Challenge: Build a system that democratizes legal document analysis — allowing anyone to upload a contract and receive a professional-grade risk assessment instantly, without needing a law degree or expensive consultants.

Goal: Create an automated workflow that accepts PDFs via Telegram or Web, extracts and chunks text for large documents, analyzes content with GPT-4o, and returns a structured JSON risk report with actionable compliance recommendations.

System Architecture

Document Processing Flow

The system uses n8n as the orchestration layer. PDFs are received via Telegram Bot API or Web interface, processed through text extraction, intelligently chunked for large documents, and analyzed by GPT-4o with a specialized legal prompt. Results are returned as structured JSON.

Telegram / Web
PDF Upload
→
n8n Workflow
Orchestrator
→
Text Extract
PDF Parsing
→
Chunking
Large Docs
→
GPT-4o
Legal Analysis
→
JSON Report
Structured
n8n
OpenAI GPT-4o
Telegram Bot API
PDF Processing
Vercel
JavaScript

Key Features

Implementation Details
Document Processing
  • PDF text extraction
  • Smart chunking logic
  • Large file handling
  • Multi-format support
AI Analysis
  • GPT-4o legal prompts
  • Risk detection engine
  • Clause identification
  • Context retention
Output
  • Structured JSON report
  • Risk severity levels
  • Compliance recommendations
  • Executive summary
JSON / Structured Report Output
{
  "document_type": "Service Agreement",
  "overall_risk": "Medium",
  "executive_summary": "Standard service contract with 
    several concerning liability clauses...",
  "detected_risks": [
    {
      "clause": "Indemnification",
      "severity": "High",
      "location": "Section 8.2",
      "issue": "Unlimited liability exposure",
      "recommendation": "Cap liability at 12 months fees"
    },
    {
      "clause": "Termination",
      "severity": "Medium",
      "location": "Section 12.1",
      "issue": "Short notice period (15 days)",
      "recommendation": "Negotiate minimum 30 days"
    }
  ],
  "compliance_flags": ["GDPR mention missing"],
  "recommendation": "Review with legal counsel before signing"
}

Results

Project Outcomes
Technical
  • End-to-end automation
  • Chunking for large docs
  • Multi-channel input
  • Serverless deployment
User Experience
  • Instant analysis results
  • No legal expertise needed
  • Mobile-friendly via Telegram
  • Clear risk visualization
Business Value
  • 90% cost reduction vs lawyers
  • Instant vs days turnaround
  • Risk mitigation tool
  • Accessible to non-lawyers