Skip to content
N

nyaya-ai

law for everyone

Created on 11th October 2026

•

N

nyaya-ai

law for everyone

The problem nyaya-ai solves

Nyaya AI eliminates the barriers of complex statutory legalese and recent criminal code transitions (IPC to BNS/BNSS/BSA) by providing Indian citizens and legal professionals with verified case law research, plain-language guidance, and automated legal drafting.

Challenges we ran into

  1. Multi-Agent Token Bursts & LLM Rate Limiting (429s) in LangGraph
    The Hurdle:
    Our multi-agent pipeline chains 5+ discrete agent nodes per legal query (Triage → Fact Extraction → Kanoon Precedent Retrieval → Legal Advisor → Action Planner → RTI Addon). During multi-turn conversations and peak testing, chaining multiple heavy or structured JSON calls quickly hit Token-Per-Minute (TPM) limits and 429 Too Many Requests rate-limit errors on our primary provider (Groq). A failure at any intermediate node broke the entire graph execution.
    How We Overcame It:
    We architected a dynamic multi-tier fallback engine in modelProvider.ts. We implemented custom error inspection (isRateLimitError) that automatically catches 429s and token exhaustion, seamlessly cascading across a priority chain from Groq (openai/gpt-oss-20b, llama-3.3-70b-versatile) to Mistral endpoints (mistral-medium-3-5, open-mistral-nemo, ministral-8b-2512). We also added graceful schema fallback: if structured JSON extraction encounters parsing issues, the node automatically falls back to raw text classification without crashing the pipeline.
  2. The Great Indian Statutory Transition (IPC/CrPC vs. BNS/BNSS/BSA)
    The Hurdle:
    India recently overhauled its criminal legal framework, transitioning from the historic Indian Penal Code (IPC) and CrPC to the Bharatiya Nyaya Sanhita (BNS) and Bharatiya Nagarik Suraksha Sanhita (BNSS). Standard LLMs frequently hallucinated cross-references, cited deprecated sections, or scrambled old and new statutes. Furthermore, Indian Kanoon’s judicial precedents are historically indexed under the legacy codes.
    How We Overcame It:
    We designed a dual-statute harmonization layer within the RAG prompt engineering for legalAdvisorNode. The agent ingests precedents retrieved from Indian Kanoon and cross-references corresponding provisions (e.g., Section 420 IPC alongside Section 318(4) BNS). We explicitly constrained generation to authenticate every legal advice point with exact Section numbers and Acts while tailoring the tone between Citizen Mode (plain English) and Lawyer Mode (procedural citations).
  3. Context Bleed & Topic Shifts in Stateful Multi-Turn Dialogue
    The Hurdle:
    In legal assistance, users frequently switch topics abruptly (e.g., beginning with a tenancy dispute and then suddenly asking about cyber fraud or domestic violence). Passing the entire conversation history into downstream nodes caused "context bleed" — the Fact Extractor and Legal Advisor attempted to reconcile mutually exclusive legal facts into a single case.
    How We Overcame It:
    We augmented the triageNode with a Zod-validated context-switch detector. By examining recent history snippets against the new query, the triage agent identifies whether the prompt is a follow-up or a topic pivot. On detection, it attaches a high-priority context_note to the LangGraph state that instructs downstream nodes to isolate and focus on the latest grievance while retaining history strictly for user context.
  4. Browser Freezing & Audio Resampling with In-Browser Whisper
    The Hurdle:
    To make legal consultation accessible for users who prefer speaking, we integrated client-side speech recognition using @xenova/transformers (Whisper). However, initializing and running ONNX model inference on the main browser thread caused noticeable UI stutter and froze the interface. Additionally, native browser MediaRecorder captures audio at 44.1 kHz or 48 kHz stereo, whereas Whisper strictly requires a 16 kHz mono Float32Array.
    How We Overcame It:
    We moved audio transcription completely off the main thread into a dedicated Web Worker (whisper.worker.js). In our useVoiceInput.js hook, we leveraged the Web Audio API’s OfflineAudioContext to automatically resample recorded audio buffers down to 16,000 Hz mono before transferring the Float32Array to the worker, ensuring the React UI remained completely smooth and responsive.
  5. Indian Kanoon API Latency & Query Throttling
    The Hurdle:
    External legal precedent lookups via the Indian Kanoon API introduced latency spikes (1.5–3 seconds per query) and were subject to API token rate limits during repetitive queries.
    How We Overcame It:
    We integrated an Upstash Redis caching layer in kanoonAPINode. Cleaned search queries derived from extracted legal facts are hashed and cached with a 24-hour TTL (setEx), dropping repeat search response times to sub-50ms and ensuring seamless mock fallbacks when API limits or network timeouts occur.

Discussion

Builders also viewed

See more projects on Devfolio