How I built NirmalAir, a GenAI clean-air assistant for Indian households, where real data decides, code calculates, and the AI is only allowed to explain.
Every November the same thing happens. The AQI app on my phone turns red, the number says 288, and the family group fills up with forwards. But a number does not tell you anything you can act on. Can the kids play outside at 5? Should Dadi skip her morning walk, or just move it? When do you open the windows, if ever? Is the bus actually better than the car, or does it just feel virtuous?
For PromptWars Virtual Challenge 6 (Urban Air Quality Assistant) I built the thing I wanted in that moment: tell it who lives in your home, and it turns today's measured air into a step for each person, with what each step changes. Meet NirmalAir: nirmal-air.vercel.app.
The one rule: AI explains, code calculates, real data decides
The organisers were clear that the AQI must never come from the model. I took that further and split the job three ways:
- Real data decides. The air quality comes only from the Central Pollution Control Board's real-time feed, from the nearest station that has a valid reading under 3 hours old. Its station, distance and measured time are always on screen. The hourly forecast is used only to rank hours against each other, never shown as the air quality.
- Code calculates, and decides. Every number is worked out by tested code: the official AQI, PM2.5, the indoor estimate with windows shut or a purifier on, commute CO₂, and even how much polluted air you breathe on the way. Code also makes the judgement calls: whether a routine moves indoors or to the cleanest hours, the windows rule, which commute swap to offer.
- The AI explains. The model gets a facts bundle (short sentences written by code, each with an id) and writes the plan in plain words, citing the fact ids it used.
What it does
Pick a sample household or describe your own in about a minute: up to eight people with their age group and sensitivities (asthma, heart condition, pregnancy), their routines, their trips, and the home. Type any place in India, or use your location.
You get a timeline for the day. The next step is set large, every step says who it is for, and its figure sits at the right edge: 1 to 4 pm, 13 µg/m³, −15.7 kg CO₂ a week. Tap The numbers behind this and you see the facts it rests on, each labelled measured, forecast, estimate or CPCB guidance.
Around the plan: a strip of the next 24 hours with the cleanest and worst three-hour windows, an Ask box ("Can Aarav play cricket at 5 pm?"), an At home panel, Getting around with the swaps, and This week, where ticking "I did this" adds up the CO₂ avoided and the change in PM2.5 breathed over seven days.
The real test: one household, one afternoon
On 27 November at 4 pm, ITO in Delhi read AQI 288 (Poor). For the Delhi family sample, code sent the model 20 facts, including these:
cleanest Cleanest time: 1 pm to 4 pm tomorrow. windows Today's rule for windows on Poor air: keep windows shut; open them briefly only during the cleanest time, 1 pm to 4 pm tomorrow. routine_1 Aarav's usual outdoor play: 5 pm, for 60 minutes. Today's rule for Poor air and a more sensitive person: move it indoors today. indoor_shut With windows shut, the main room is about 78 µg/m³, 33% below outdoors. indoor_purifier With windows shut and the purifier on, about 13 µg/m³: about 0.6 cigarettes a day instead of about 5.3 outdoors. The model wrote, among other steps: "Keep windows shut; open briefly only during the cleanest time, 1 pm to 4 pm tomorrow", citing windows, cleanest and indoor_shut. Every number in it is in a cited fact, and before it reached the screen, code checked exactly that. Every plan and answer has a How this was generated panel with the model, the prompt version, the facts sent and the raw reply, so nobody has to take my word for it.
The bloopers (or, why judgement kept moving into code)
The first versions let the model make more decisions. Live testing changed that, one mistake at a time:
- It picked "2 pm" inside the cleanest window and added "10 minutes" of its own. A number guard now rejects any number (digits and number words, in English and Hindi) that does not appear in the facts.
- It moved an asthmatic grandmother's walk to the "cleanest" hours on Very Poor air. Code now decides each routine from CPCB's health bands; the AI only explains the rule.
- It told a father with a heart condition to take the bus, which meant 371% more polluted air on the way. Code now ranks the swaps, and sensitive people are offered the ones that do not add exposure first. For him, that is the carpool.
- It said to shut the windows during the cleanest window, exactly when they should be open. Code now decides the windows rule.
- Asked for Hindi, it sometimes answered in English. Code now checks for Devanagari and sends the answer back.
- An independent review caught it skipping a carpool swap and turning "2 pm to 5 pm" into "at 2 pm". Code now checks that every commute's chosen swap is offered and that the cleanest time is quoted whole, with "tomorrow" when it is.
The pattern held all the way through prompt version 7: every time the AI made a judgement call wrong, the judgement moved into tested code, and the AI was left to explain it. A failed answer is sent back once with the exact problem, then to the next model, and if every model fails, the page shows rules-based advice clearly labelled Standard advice (not AI-generated).
Honest about indoors
The explainer session mentioned plants, so I looked it up properly. A 2019 review of chamber studies (Cummings and Waring) found it would take 10 to 1,000 plants per square metre to match a building's normal air exchange. So NirmalAir says it plainly in the At home panel: houseplants do not measurably clean a room's air; the windows rule and a purifier do. Indoor values are estimates from outdoor air, and the page says so.
Made for Indian homes
- Anywhere in India. The nearest station comes from a stored list of 571 CPCB stations; older names like Bangalore and Gurgaon work. If the nearest station is far (Nirmal's is about 110 km away), the page says the local air may differ.
- Hindi. "योजना हिंदी में" asks for the plan and answers in Hindi.
- For communities too. Share today's air copies a short summary (the AQI, when and where it was measured, the cleanest and worst hours) for a building, school or society group. Code writes it, not the AI.
A page that follows the sky
This is my favourite detail. At the top of every plan is a band of sky for the place you chose. Code works out sunrise and sunset for that spot, so the sun climbs and sets on its real path, the clouds come from the actual cloud cover, and it rains in the band when it is raining there. After sunset the page turns to dusk and then midnight blue, with the moon and stars.
One place, one day: 9:30 am, 1 pm, 4:30 pm, 6:30 pm and 9:30 pm.
The whole page follows along, and the measured AQI dulls the colours toward smog: on a Very Poor day the sky looks greyer, and there are fewer stars at night. It is decoration only, never carries information you need, and stops moving for anyone who prefers reduced motion. If you would rather choose, the switch in the top bar pins light or dark colours without reloading the page.
Built with AI, too
I built NirmalAir with an AI coding agent, and I used Gemini in Google Antigravity for an independent review of the code and the problem alignment. Inside the app, Groq's gpt-oss-120b usually writes the plan in a few seconds, with Gemini 3.5 and 3.1 Flash-Lite as backups on separate quotas.
What I decided: the data sources (CPCB first, the forecast only for timing), no database (the household lives in a signed cookie in your own browser), the name, the look (including the idea that the page follows the sky), and every approval before code. What the AI did under my review: research into the published sources (read from the PDFs themselves), the code and tests, live checks against CPCB and the models, and design reviews.
How I checked it
- 376 tests at 100% branch coverage, with CPCB, Open-Meteo and the models mocked from recorded replies, plus 38 browser tests: real journeys, axe checks for WCAG 2.2 AA in light and dark, 320 px phone widths, keyboard use and a clean console.
- Accessibility: a skip link, visible focus, form errors that take focus and link to their fields, reduced motion respected, and text contrast tested in every sky colour at every haze level.
- Security: a strict Content Security Policy with no inline code, CSRF tokens on every form, rate limits on every route, a 16 KB request limit, and keys only in environment variables. CodeQL, pip-audit and gitleaks run on every push. Everything the app holds and sends is listed in SECURITY.md.
What it can't do (yet)
- No accounts or sync across devices: the household lives in one browser.
- Indoor values are estimates from outdoor air, not sensor readings.
- The number guard proves every number came from the facts, not that it was used in the right place. That is why each step shows the facts it cites.
- Hindi covers the plan and answers; the rest of the interface is still in English.
- It is not medical advice: it says when to keep medicines handy or see a doctor, and nothing more.
Try it
- App: nirmal-air.vercel.app. Pick the Delhi family, then ask it something.
- Code and docs: github.com/Mitali-Patle/nirmal-air
If you live with a child who loves the evening cricket match, or a grandparent who will not skip the morning walk, I hope it helps you decide what to do today, and not just how bad the air is.




