Inspiration
Millions of workers in Delhi — construction labourers, domestic workers, factory hands, migrants from other states — are routinely underpaid, wrongfully terminated, or denied PF/ESI contributions. Most don't know the law protects them. Those who do don't know which office to go to, which form to fill, or how to write a complaint. Government websites are in English. Legal aid is inaccessible. The power imbalance is enormous.
We wanted to build something that works for the worker, not the bureaucracy — an assistant that speaks their language (literally), knows the law cold, and turns that knowledge into something actionable in under two minutes.
What It Does
Haq is a Hindi-first AI chat assistant for Delhi workers with four core capabilities:
1. Grounded rights chat — ask in plain Hindi or English about unpaid wages, workplace injury, wrongful termination, PF/ESI, e-Shram, or any labour issue. Haq answers simply, names the exact law (Code on Wages 2019, BOCW Act, Employees' Compensation Act…), and ends every answer with a concrete next step. Answers are grounded via Google Search so wage figures and scheme details stay current — and every answer shows its cited sources.
2. Minimum wage calculator — pick your work category (unskilled / semi-skilled / skilled / clerical) and see exactly what Delhi law guarantees you per month and per day. Enter what you're actually paid — it instantly shows your shortfall and lets you ask the assistant what to do next.
3. Formal complaint drafter — fill in a short form (issue type, employer, what happened). Haq generates a complete, ready-to-submit complaint letter addressed to the correct authority (Labour Commissioner, BOCW Board), citing the applicable law, with required documents listed and submission instructions. Download it as a .txt file to print and hand in.
4. Helplines & resources — one-tap access to Shramik Helpline 155214, e-Shram Helpdesk 14434, the Delhi BOCW Welfare Board, and the SAMADHAN online grievance portal.
The app is a fully installable PWA, bilingual (Hindi/English with instant switching), screen-reader accessible, and stores absolutely nothing — no accounts, no database, no personal data.
How We Built It
Frontend: Next.js 16 (App Router) + React 19 + TypeScript. Tailwind CSS v4 for styling, with a custom design system tuned for high-contrast, high-legibility, low-literacy-friendly UI. Three Google Fonts: Lexend (headings, optimised for reading ease), Source Sans 3 (body), and Noto Sans Devanagari (Hindi script — which needs extra line-height for vowel marks above letters).
AI layer: Google Gemini 2.5 Flash via @google/genai . We use two separate API calls by design — one for chat (streaming + Google Search grounding for live citations) and one for complaint generation (strict JSON responseSchema for guaranteed structure). These two features can't be combined in one Gemini call, so the architecture explicitly separates them.
Knowledge core: lib/knowledge.ts — a curated, sourced TypeScript data file containing real Delhi minimum wage rates (as of April 2025), all key labour statutes, helplines, welfare schemes (e-Shram, BOCW), and office addresses. This is injected into every system prompt so the AI always has correct baseline facts even when web grounding is unavailable.
Streaming: The chat API route returns NDJSON over a ReadableStream . Text chunks stream to the browser in real time as Gemini generates them. Source metadata is sent in a final frame.
Evals: An automated testing system ( evals/ ) hits the live API with real-world worker questions and grades responses two ways — deterministic checks (does the answer contain the correct wage figure? the helpline?) and an LLM judge (is it plain enough? does it cite the law? safety-first on injuries?). A "Ralph loop" runs this, reflects on failures, rewrites guardrails into a prompt.override.md file that the server reads at request time — no restart needed.
Challenges We Ran Into
• The two-call constraint: Google Search grounding and structured JSON output ( responseSchema ) cannot be used in the same Gemini API call. We discovered this the hard way and had to redesign the architecture — chat uses grounding, complaint generation uses schema, and the two never mix.
• Grounding on the free tier: Google Search grounding requires a billing-enabled project. We needed the app to work gracefully for anyone running it with a free key. The solution: try grounding first, catch the 429, fall back to the curated knowledge core silently — the user still gets a useful answer.
• Hindi typography: Devanagari script has vowel marks (matras) that extend above characters and need more vertical space than Latin text. Getting line-heights, font stacking, and text rendering right for both scripts simultaneously took real iteration.
• Tone calibration: Getting the AI to speak like a trusted friend to a low-literacy worker — not a lawyer, not a bureaucrat — required careful prompt engineering and multiple eval cycles. "Name the law" and "be warm, never condescend" had to be explicitly balanced.
• Safety-first ordering: An injured worker asking "what are my rights?" must first hear "call 112 now" — not a legal explanation. Building that unconditional ordering into the system prompt and then verifying it with evals was a non-trivial challenge.
Accomplishments That We're Proud Of
• Works without grounding: The curated knowledge base means a worker with a free Gemini key gets accurate, legally-grounded answers — not hallucinated figures. The AI is explicitly instructed to never invent a wage rate or law section.
• The complaint drafter is genuinely production-quality: It addresses the right authority, cites the right law by name, uses [square bracket placeholders] exactly where the worker needs to fill in details by hand, and lists the specific documents to attach. A worker can print it and walk into the district labour office.
• Self-improving AI: The Ralph eval loop means the system can improve its own behaviour by running test cases, reflecting on failures, and rewriting guardrails — a lightweight, practical version of RLHF without the infrastructure.
• Zero data footprint by design: No database, no user accounts, no logging of what workers type. Privacy as a first-class requirement, not an afterthought — especially important for users who may be undocumented or fear retaliation.
• Fully accessible PWA: The app installs to a home screen, works offline for the shell, is keyboard-navigable, has screen reader labels throughout, respects reduced-motion preferences, and handles iOS safe-area insets correctly.
What We Learned
• AI + hard-coded knowledge is stronger than AI alone. A curated, sourced, regularly-dated knowledge file injected into the prompt beats relying on the model's parametric memory for high-stakes factual domains like labour law. The model reasons better when it's given the facts rather than asked to recall them.
• Prompt architecture matters as much as prompt content. Separating concerns — who the AI is, how it speaks, what every answer must contain, what facts it knows, what override refinements exist — into distinct sections made the prompt maintainable and testable.
• The "two-call design" pattern is broadly useful. Whenever you need grounded/streamed output for one feature and structured/deterministic output for another, splitting into separate API calls with different configurations is cleaner than trying to cram everything into one.
• Evaluation as iteration fuel. Having concrete, automated tests for AI behaviour (not just vibes) makes prompt engineering feel like software engineering. The Ralph loop made us think about AI quality the same way we'd think about test coverage.
What's Next for Haq
• Voice input — a significant portion of the target audience is more comfortable speaking than typing. Web Speech API integration is partially scaffolded ( micStart , micListening strings already exist in i18n).
• Elasticsearch integration — the knowledge lookup in lib/knowledge.ts is intentionally designed as a drop-in replacement point. Connecting it to an Elasticsearch cluster would enable semantic search over a richer corpus of case law, scheme notifications, and office circulars.
• Offline-capable answers — caching the knowledge base in a service worker so workers in low-connectivity areas can still get answers to common questions.
• More states and cities — the minimum wage and welfare board structure currently covers Delhi. Extending the knowledge base to Haryana, UP, Maharashtra, and other high-migration states would multiply impact.
• WhatsApp / SMS channel — most target users are on WhatsApp. A Twilio or Meta API integration would let the same AI agent work over WhatsApp messages — no app install required.
• Verified legal partner — connecting Haq to a legal aid organisation (like DSLSA — Delhi State Legal Services Authority) so high-severity cases can be escalated to a real lawyer automatically.
Built With
- api
- gemini
- nextjs
- typescript
Log in or sign up for Devpost to join the conversation.