PRODUCT / INTERNAL BUILD

AI Legal Assistant for Indian Law — multi-model agent chat

A Flask Progressive Web App that treats Indian law as a product surface: jurisdiction, BNS / BNSS / BSA and adjacent domains, guided wizards, document drafts, and a model picker that can stay on the machine. Not a chatbot skin. Not legal advice.

FlaskSQLitePWABootstrap 5Tailwind CSSHugging FaceDeepSeekOpenAI / Claude (optional)BNS · BNSS · BSA
Industry
Indian legal-tech / public legal information
Type
Domain AI agent + CMS + optional offline LLMs
Role
Architecture + full-stack + model integration
Models (this session)
DeepSeek online · HF Llama 2 7B / Mistral 7B / GPT-2 offline
Stack
Flask · SQLite · Bootstrap 5 · Tailwind · PWA
Proof
Landing, agent chat, jurisdiction, admin CMS
Bharatiya Nyaya Sanhita legal agent chat with jurisdiction, category, guided wizards and document draft actions

The chrome is the product: jurisdiction, legal category, wizards and drafts sit next to the model agent chat. Public copy on the landing still says “legal advisor”; the in-app notice is the contract that matters — this software does not provide legal advice.

Product walkthrough

The same system on video — public landing through the BNS agent chat, model picker and admin. It is a walkthrough, not a court filing and not a licence to practise.

Open the dedicated demo page → · Watch on YouTube →

The problem

Most “AI for law” demos are a hosted chat box with a gavel icon. That fails the moment the work is Indian, local, and sensitive:

Constraints

Delivery stayed inside the client's stack, tenancy, compliance and media-ownership boundaries. Where a choice was forced (suite vs owned plane, BYOC vs CPaaS, local vs cloud models), the architecture section below records the trade-off rather than a marketing rewrite.

  • IPC-era prompts still circulating after BNS, BNSS and BSA replaced the older codes
  • No court level, state or district on the question — so the model answers as if India were one forum
  • Every token leaving the building because the only model is a public API
  • No operator path to curate questions, categories or keys without shipping a new frontend
  • Drafts (FIR, consumer complaint, notice) living in Word templates beside the chatbot instead of in the same session

A generic LLM that “knows Indian law” is the wrong product. The hard parts are domain structure, jurisdiction as input, model residency, and a CMS so legal content is not hardcoded in HTML.

Business requirements

One path for a visitor: land, understand the six public domains, start chat, pick a model, set where the matter sits, use a wizard or a document draft, and read the disclaimer. One path for ops: pages, categories, questions and API keys without touching the agent UI. Local Hugging Face models where data should not leave; API models where latency and quality need a hosted endpoint.

This page does not publish invented accuracy scores, “cases won,” or a claim that the product is a law firm. The engineering claim is a complete surface map.

The solution

Flask owns routes, sessions and model loading. SQLite is the system of record and travels with the app — no separate database server for this build. Bootstrap 5 plus Tailwind render a public landing, the agent workspace and the admin panel. A service worker and web app manifest make the UI installable as a PWA.

Three audiences, one codebase:

  • Visitors — landing, category grid, features, chat
  • Researchers / clerks — jurisdiction, category, suggested questions, wizards, document drafts, model switch, session history
  • Admins — pages, categories, questions, encrypted API-key store

The public shell is marketing that matches the product: “Your Guide to Indian Law,” Start Chatting, Learn More, Admin. Feature cards on the same site: instant answers, expert guidance, 24/7, coverage across the six domains, private & secure, PWA support.

AI Legal Assistant public landing: Your Guide to Indian Law, Start Chatting, Learn More and Admin Login
Why Choose Our AI Legal Assistant: instant answers, expert guidance, 24/7, comprehensive coverage, private and secure, PWA support
Explore Legal Categories: BNS criminal law, BNSS procedure, BSA evidence, Family Court, Consumer Rights, Employment Rights

How the system flows

Users pick jurisdiction and category; the agent retrieves Indian law context and drafts documents — chat and wizards share one backend.

flowchart TD
  User[User login or guest] --> J[Jurisdiction BNS category]
  J --> Chat[Chat or wizard]
  Chat --> RAG[RAG legal corpus]
  RAG --> LLM[LLM draft answer]
  LLM --> Doc[Document draft export]
Legal assistant session flow.

Architecture

The model is a worker. Jurisdiction, category and curated Q&A are the product. Retrieval here is structured content plus prompts — this page does not claim a vector database.

flowchart TB
  UI[Web chat wizards]
  API[Backend auth sessions]
  VDB[(Vector or document store)]
  LLM[LLM provider]
  UI --> API
  API --> VDB
  API --> LLM
AI Legal Assistant architecture.

Key components

Backend

Flask application, SQLAlchemy models, session chat, model registry, jurisdiction and wizard payloads, document-draft templates, admin auth.

Frontend

Bootstrap 5 + Tailwind. Public landing, agent workspace, admin. PWA manifest and service worker for install and basic offline shell.

Models

Hugging Face conversational / text-generation models locally. DeepSeek as an online API in this session. OpenAI and Claude as configured providers — not claimed as live in the capture if they were offline.

CMS

Dynamic pages, six legal categories, curated questions with short and full answers, API-key rows encrypted at rest and never displayed in full.

What the agent actually covers

Jurisdiction and location

The left rail is the difference between a legal product and a prompt. Jurisdiction level, state and district are first-class. This session set Panchayat and Karnataka; the district list loaded Bangalore Urban, Mysore, Hubli, Mangalore, Belgaum, Gulbarga, Davanagere, Bellary, Bijapur, Raichur. Copy under the list: escalate to BDO if Panchayat cannot resolve. Important notes state that Panchayat handles local civil disputes, property matters and minor criminal cases. State information lists Karnataka High Court, the State Legal Services Authority, and the State Consumer Commission.

Legal agent with Panchayat jurisdiction, Karnataka selected and district dropdown listing Bangalore Urban, Mysore, Hubli and other districts

Legal category, wizards and drafts

Category in this capture: BNS — Bharatiya Nyaya Sanhita (Criminal), marked Beta. Guided wizards: Criminal, Civil, Consumer, Employment. Generate Documents: FIR Draft, Consumer Complaint, Legal Notice. Suggested questions change with category — the BNS view in another capture showed family-court prompts as well, because the suggestion list is category-driven, not a single hardcoded FAQ.

The chat pane is labelled Legal Assistance Chat / AI Model Agent Chat. History can be cleared. Export and share sit in the header. The public-resources strip repeats the disclaimer in the same viewport as the composer.

Model switching

Select Model is a first-class control, not a deploy-time flag. This session listed:

  • DeepSeek — Online
  • Llama 2 7B (Hugging Face) — Offline, gated, token set
  • Mistral 7B (Hugging Face) — Offline, gated, token set
  • OpenAI GPT-2 Large / GPT-2 XL (Hugging Face) — Offline
  • Hugging Face GPT-2 — Offline

The workspace showed “Online — API models available” when DeepSeek was reachable. This page does not claim GPT-4, Claude-3, or any model that was marked Offline in the capture. OpenAI and Claude remain supported providers in admin when keys exist.

Select Model dropdown showing DeepSeek online and Hugging Face Llama 2 7B, Mistral 7B and GPT-2 variants offline

Admin CMS

Ops is not a second repo. The admin shell: Dashboard, Pages, Categories, Questions, API Keys, View Site.

  • Dashboard — this session: 1 page, 6 categories, 0 questions in the counter yet, 1 published. Quick actions to create page, category or question. System info: AI Legal Assistant, version 1.0.0, Active
  • Categories — BNS, BNSS, BSA, Family Court, Consumer Rights, Employment Rights with slug, icon, colour, Active, sort order 1–6
  • New category / question — name, slug, description, icon, colour, sort; question fields include category, short answer for preview, full answer, keywords JSON, featured flag
  • API keys — OpenAI, Claude (Anthropic), DeepSeek as supported providers. Keys encrypted at rest, never displayed in full, usage counted
Admin dashboard for AI Legal Assistant showing page, category, question and published counts
Manage Categories table listing BNS, BNSS, BSA, Family Court, Consumer Rights and Employment Rights
Manage API Keys screen with OpenAI, Claude and DeepSeek as supported providers and no keys configured

The API-keys table in this run was empty (“No API keys configured”). DeepSeek still appeared Online in chat — provider wiring and a filled admin row are not the same screenshot. This page does not invent a live OpenAI or Claude session.

Data model (what matters)

Identity: admin users. Content: pages, page sections, categories, questions. Chat: sessions and messages with optional context summaries. Ops: model context rows and API-key records. Relationships are ordinary: a category owns questions; a session owns messages. SQLite file lives in the instance folder so backup is a file copy — credentials for local bring-up are not published here.

Engineering challenges

  • Domain, not vibes — BNS/BNSS/BSA and four adjacent domains as CMS rows, not a single system prompt
  • Place matters — Panchayat vs district vs higher courts changes the next step; the UI has to collect it
  • Residency — local Hugging Face weights vs API models in the same picker
  • Keys in the product — store OpenAI / Claude / DeepSeek without echoing secrets back to the grid
  • Honesty — marketing “advisor” copy vs the in-app “does not provide legal advice” notice

How those were solved

Categories and questions are tables. Jurisdiction selectors feed the agent context. The model registry reports Online vs Offline (and gated/token state) so operators do not guess. Admin key screens mask on read. The disclaimer is in the chat rail, not only in a footer.

My role

Architecture + full-stack + model integration. Flask app and schema, public PWA, agent workspace, jurisdiction and wizard flows, document drafts, Hugging Face and API model switching, admin CMS. Live client matters stay off this page.

ArchitectureFlaskSQLite schemaPWAMulti-model chatIndian-law CMSJurisdiction UXAdmin keys

Technology stack

FlaskSQLAlchemySQLiteBootstrap 5Tailwind CSSPWA / service workerHugging Face TransformersDeepSeek APIOpenAI (optional)Anthropic Claude (optional)

These technologies are the documented stack. This page does not add vector databases, GPT-4, or court integrations that were not part of the captured build.

Production considerations

  • RAG corpus versioning for Indian law updates — not legal advice disclaimers only.
  • Prompt and retrieval logs for audit without leaking client uploads.
  • Rate limits on document ingestion endpoints.

Engineering outcomes

No invented “legal accuracy %” or user counts. What this system actually established:

  • A public path from landing → six Indian-law categories → installable PWA chat
  • An agent shell where jurisdiction, category, wizards and document drafts are visible before the first token
  • A model picker that reports DeepSeek online and Hugging Face models offline in the same session
  • An admin path for pages, categories, questions and masked API keys
  • SQLite as an offline-capable store — no remote database server required for this build
  • A product disclaimer in the same viewport as the composer

Screenshots

Architecture on this page is the HTML diagram above. The walkthrough is also on the AI Legal Assistant demo page and in Next-gen AI legal chatbot for India.

Architectural insight

A legal assistant is a jurisdiction, a domain catalogue and a model that you can keep local. If the LLM owns the forum and the statute, you do not have a product you can defend. If SQLite owns categories and questions, the UI owns place, and the model only answers inside that frame, you do.

Disclaimer: this software is for information, research and drafting workflows. It is not a law firm, not an advocate, and not legal advice. Nothing here is a filing, opinion or representation before any court or authority. Vendor names (Hugging Face, DeepSeek, OpenAI, Anthropic) are described as advertised integrations in this build.

FAQ — buyer & architecture questions

Ten common questions about this case study, fit, and engagement.

Documented barge-in, multilingual fallback, tool use or telephony integration—not a demo webhook only.

No. Asterisk/FreeSWITCH handles media; AI orchestration sits beside call control.

Yes. Narrow IVR replacement or receptionist is a common first phase.

Retention and redaction policies are set per project; we implement access control and storage limits.

Architecture can route providers; latency and data residency drive the choice.

Call flows, CRM, languages, compliance rules and example calls that fail today.

Share the current stack (PBX, CRM, cloud), the failure or goal in one paragraph, peak call volume, carriers, and any deadline. Screenshots, a pcap, or a short Loom beat a 40-page RFP. Use the project brief or email hello@unifiedpbx.in.

Yes. Delivery is remote-first from Delhi with scheduled overlap for EU, UK, US and APAC stand-ups. Production changes use written runbooks, rollback steps and agreed maintenance windows.

Yes. Many engagements begin with a 1–2 week SIP trace review, tenant-isolation audit, or architecture assessment. If the fit is good, scope expands from evidence—not from a generic sales deck.

Founders, CTOs, telecom leads, MSPs and product teams building or fixing UCaaS, CCaaS, CRM+voice, AI voice, or vertical SaaS—not buyers who only need seats on a mass-market suite.

Building a domain AI assistant — legal or otherwise?

Share the statutes or playbooks, whether inference must stay on-prem, and whether operators need a CMS. The first reply is whether the gap is jurisdiction UX, local models, document drafts or admin.

Discuss Your Project