Inspiration
AI is starting to change education, but most tools stop at grading faster. We wanted to use it for something more important: making sure no student is misunderstood.
Every exam ends with a score, but a score hides almost everything that matters. Two students can both get 35 out of 50 for completely different reasons: one misunderstood a concept, the other made calculation slips. Too often, a student who scores low is simply seen as a "weak student". The mark says how much they got wrong, but not where they went wrong or why. Every student has strengths, and a score alone hides them.
Teachers want to know more than who passed. They want to know whether their class has truly understood a topic, well enough to apply it in real life without confusion, and what to change in their teaching when it hasn't. That information already exists in piles of answer sheets, but after hours of marking, there's no time left to read them for patterns.
We wanted to change what a test produces: not just a mark for each child, but a clear picture of what the class didn't understand, why, and what to teach next. We also knew children's work shouldn't be sent off to a server to get there.
Gemini Nano running in Chrome made that possible. The handwriting is read on the teacher's own laptop, and only public material, like the question paper, goes to the cloud.
So RedPen isn't just a marking tool. It's a system for understanding students. It shows each student's strengths and areas to improve, finds the concepts the class didn't understand, and helps the teacher replan with a reteaching lesson plan and practice questions. The next test shows whether the gap has closed.
A test tells you the score. RedPen tells you about the student.
What it does
RedPen turns students' handwritten answer sheets into insight. It shows what each student and the whole class didn't understand, why, and what to teach next. Children's work is read on the teacher's own laptop by Gemini Nano, while the cloud only handles public material.
1. Answer key and marking scheme
- Upload the question paper as a PDF or text file, plus the syllabus chapter.
- Add your own answer key, or let RedPen draft one in the cloud from the question paper.
- Each question gets marking points, "look for" phrases, common mistakes, a worked solution and, on request, an illustration.
- Every question is tagged with its topic, concepts, Bloom level and skill type (recall, explain, calculate, diagram, write).
- The teacher edits anything, approves the key, and chooses strict or lenient marking.
2. Answer sheets
- Enter the class list and upload photos of each student's sheet.
- Draw a box over the name area once, and it's blacked out on every page before any AI sees it.
- Gemini Nano reads the handwriting on the laptop. If a sheet has a problem, or the laptop can't run Nano, the teacher can type the answers in by hand.
3. Review and marking
- Red-pen marks appear beside each answer, quoting the student's own words as evidence.
- Code checks every quote against the answer, and checks every calculation.
- The teacher changes any mark with one tap and confirms each sheet. Totals use only teacher-confirmed marks.
4. Feedback for students
- For each lost mark, an on-device note covers what the student wrote, the correction, and why it matters.
- There's an overall note, and a printable marked copy of the sheet.
5. Class insights
- Concepts are ranked by the share of students who lost marks.
- Each concept shows how many students were partly right, mixed it up, or missed it, plus the most common mix-up.
- Follow-up shows whether a topic flagged earlier has improved since the last test.
- Any group of fewer than 5 students is hidden.
6. Reteaching lesson plans
- Pick the weak concepts, the number of periods and their length.
- RedPen drafts a period-by-period plan: concepts, learning objectives, Bloom-tagged outcomes, the 5E teaching process (Engage, Explore, Explain, Elaborate, Evaluate), assessment, resources and 21st-century skills.
- It includes practice questions with answers.
- Copy it, download it as a PDF, or save it. The teacher can see exactly what was sent to the cloud: concept names and rounded class percentages only.
7. Student profiles
- After 3 confirmed tests, each student gets a report: average by subject compared with the class, strengths, areas to improve, repeated mix-ups, a breakdown by skill type, and test history.
- It finds patterns across subjects, for example strong at explaining and diagrams but losing marks on recall and calculation.
- A summary for the teacher is written by Gemini Nano on the laptop, using no names.
- A private teacher note stays on the laptop.
- It never ranks students, labels them or screens for learning conditions.
8. School view for heads of department
- Teachers choose to publish class-level counts only.
- Heads of department see a heatmap across sections and a list of concepts weak in two or more sections, so a whole department can reteach together.
9. Where AI runs
- A routing table shows which tasks run on the laptop and which in the cloud.
- It shows Gemini Nano's status, with a button to prepare the on-device model.
- A log records every AI call, with its purpose, where it ran and how long it took. It never records content.
- There's no silent fallback. If student work ever needs the cloud, the teacher must approve the exact masked image first.
10. Dashboard and demo
- A tests dashboard tracks progress across all tests.
- A fictional demo class comes with pre-loaded tests across four subjects, so anyone can try every feature.
- One button deletes a test's student data from the laptop.
How we built it
RedPen is a Chrome web app built on Firebase AI Logic's hybrid inference. The core idea is a hybrid that is both strict and smart:
- Strict: children's work never goes to the cloud unless the teacher explicitly approves it, and this is enforced in code, not just in prompts.
- Smart: each model does the job it's best at. The cloud plans, the device applies, and code checks everything.
Architecture at a glance
PUBLIC MATERIAL CHILDREN'S WORK
question paper · syllabus · key handwritten sheets · roster · notes
│ │
▼ ▼
┌──────────────────────────────┐ ┌──────────────────────────────────┐
│ Gemini (cloud) │ │ Gemini Nano (on the laptop) │
│ ONLY_IN_CLOUD │ │ ONLY_ON_DEVICE │
│ • answer key + scheme │────▶│ • read handwriting │
│ • "look for" phrases │plan │ • check each marking point │
│ • solutions, diagrams │ │ • feedback, student summary │
│ • lesson plans │ └───────────────┬──────────────────┘
└──────────────────────────────┘ ▼
▲ ┌──────────────────────────────────┐
│ │ Code checks (pure TypeScript) │
│ │ evidence · arithmetic · totals │
│ └───────────────┬──────────────────┘
│ ▼
rounded class %│ ┌──────────────────────────────────┐
+ concept names│ │ Teacher confirms every mark │
│ └───────────────┬──────────────────┘
│ ▼
│ ┌──────────────────────────────────────────────┐
└────────│ Outbound guard → Firestore │
│ class counts only, groups under 5 rejected │
└──────────────────────────────────────────────┘
All student data lives in IndexedDB on the laptop. App Check on every call.
1. A strict hybrid: privacy enforced in code
- Only two inference modes. Student work uses
ONLY_ON_DEVICE, and public material usesONLY_IN_CLOUD. ThePREFER_*modes are banned, and a test scans the codebase for them, so silent fallback is impossible. - One gateway.
hybrid.tsis the only file that creates a model, and every AI call passes through it. - Consent before cloud. If Nano is unavailable for student work, the app throws
NeedsConsentErrorand shows the teacher the exact masked image that would be sent. - Checked after every call. The SDK's
inferenceSourceis checked on each response. A cloud answer to a student-data call without consent throwsPrivacyViolationError. - Names masked first. Every page is shrunk to 1024 px, and the name area is blacked out before any model sees it.
- Outbound guard. Every payload leaving the laptop passes an exact list of allowed fields, then a scan for roster names, roll numbers, transcript lines and quotes.
- Rules on the server too. Firestore rules reject any group of fewer than 5 students. Lesson plans only receive concept names and class percentages rounded to the nearest 10%.
- App Check (reCAPTCHA Enterprise) is enforced on both AI Logic and Firestore.
2. A smart hybrid: cloud plans, device applies
Nano is fast and private, but weaker at open-ended judgement. So we split the work by strength:
- Cloud plans. Gemini reads the public question paper and drafts the marking scheme, with 2 to 4 "look for" phrases for every marking point, plus common mistakes, Bloom levels and skill tags.
- Device applies. Nano checks one marking point at a time against the student's answer, guided by those phrases. Each decision is small and focused.
- Code verifies. Results are checked before the teacher sees them.
One JSON schema is shared by both backends (responseConstraint for Nano, responseJsonSchema in the cloud), so both models return the same structure.
What this changed on our test set:
| Measure | Before | After |
|---|---|---|
| Nano error per answer | 0.75 marks | 0.45 marks |
| "Check this" flags | 31 | 10 |
| Marking time | 764 s | 218 s |
3. Code checks the AI
- Evidence: every "got" or "partly right" must quote the student's answer. Numbers and short words must match exactly. Anything unverified is flagged "Check this".
- Arithmetic: equations are evaluated by a small, safe parser, not by the model. A wrong result becomes a calculation slip.
- Totals: calculated in code from teacher-confirmed marks only.
- The teacher decides every mark.
4. Clean, testable structure
| Folder | Role |
|---|---|
ai/ |
All model calls. hybrid.ts is the only model factory. |
core/ |
Pure logic with no Firebase or browser code: verifier, arithmetic, splitter, aggregation, outbound guard |
marking/ |
On-device processing queue and feedback generation |
data/ |
Firebase setup, the only Firestore writer, and IndexedDB storage |
ui/ |
The screens |
Tech stack
| Layer | Tools |
|---|---|
| Frontend | React 19, Vite, TypeScript, small hash router, no UI library |
| On-device AI | Gemini Nano via Chrome's Prompt API, with image input |
| Cloud AI | Gemini 3.8 Flash, thinking level low |
| AI routing | Firebase AI Logic, firebase/ai hybrid SDK |
| Firebase | App Check, Anonymous Auth, Cloud Firestore, Hosting |
| Libraries | pdfjs-dist, idb, Vitest, fast-check |
Testing and measured results
- 72 tests in 17 files. These include property tests for the verifier, arithmetic checker, aggregation and outbound guard, plus boundary tests confirming that
ai/never touches Firestore, that only one file creates models, that noPREFER_*modes exist, and thatcore/stays pure. - Nano handwriting reading (developer-written sheets): 95.3% word accuracy, 99% digit accuracy.
- Speed on the laptop: about 6 s per page to read, and about 2 s per marking decision.
- Answer key: found 35 of 35 questions, and the multiple-choice key matched the official key 20 out of 20.
- Real exam scripts (50 students, 179 pages, cloud path): 94% of answered questions located, and student totals correlated with the teacher's at r = 0.76.
Accomplishments that we're proud of
A hybrid that keeps its promise in code Children's work stays on the laptop, and that's enforced by the code itself, not by a setting or a prompt. Only two inference modes are allowed. Every call goes through one gateway, the source of every response is checked, and a cloud answer without the teacher's consent throws an error. We're proud that the privacy promise can be tested.
"Cloud plans, device applies" works Splitting the job between the two models made Nano noticeably better at marking:
- error per answer fell from 0.75 to 0.45 marks
- "Check this" flags fell from 31 to 10
- marking time fell from 764 s to 218 s
Gemini Nano reads real handwriting On our developer-written test sheets, Nano read handwriting with 95.3% word accuracy and 99% digit accuracy, at about 6 seconds per page, entirely on the laptop.
It held up on real exam scripts On 50 students' scripts (179 pages, cloud path), RedPen located 94% of answered questions, and its totals correlated with the teacher's at r = 0.76. The drafted answer key found all 35 of 35 questions, and its multiple-choice answers matched the official key 20 out of 20.
More than a marking tool RedPen goes from a question paper to marked sheets, to class insights, to a reteaching lesson plan with practice questions, to a follow-up showing whether the gap closed, to a report for each student across subjects. It covers a complete teaching cycle, not a single feature.
Insight without labels Every student report describes where marks are lost and what the student is good at, never what the student "is". There are no rankings, no screening for learning conditions, and school-level data is counts only, with small groups hidden.
The AI is checked by code Every suggested mark quotes the student's own words, code verifies the quote and the arithmetic, and the teacher confirms every mark.
Solid engineering 72 tests in 17 files, including property tests for the verifier, arithmetic, aggregation and outbound guard, plus boundary tests that keep the architecture honest.
What we learned
Hybrid is a design decision, not a fallback The real value of hybrid inference came from deciding, task by task, what's private and what's public. Children's work runs on the device, public material runs in the cloud, and nothing switches between them without the teacher knowing.
Privacy has to be enforced in code A promise in the README isn't enough. Banning certain modes, routing every call through one gateway, checking where each response came from, and testing those rules gave us a privacy guarantee we can actually show.
Never let the AI have the final word Making every result quote the student's own words, checking arithmetic in plain code, and having the teacher confirm every mark made the system more trustworthy, and more accurate, than trusting the model alone.
Insight is more useful than a score Once answers were broken down by concept and skill, the patterns became obvious: whole sections making the same mistake, students strong at explaining but slipping on calculations. A score hides all of that.
How you describe students matters It's easy for analytics to turn into labels. We learned to describe where marks are lost, never what a child is, and to hide small groups so no student can be singled out.
On-device AI is powerful, but setup is still a hurdle Hardware requirements, model downloads and changing Chrome flags meant we had to build clear status screens and a consent-based cloud path, so anyone can still use the app.
What's next for Red-Pen
1. Pilot with real teachers Test RedPen with a few schools and coaching institutes over a full term. We want to measure how much marking time it really saves, and whether reteaching actually closes the gaps it finds.
2. More platforms Bring the same hybrid design to Android tablets, using Gemini Nano on supported devices, so teachers can photograph and review sheets wherever they mark.
3. Messier handwriting and diagrams Improve reading of rushed handwriting, crossed-out work and labelled diagrams, while keeping the same rule: anything the model can't verify is flagged, never guessed.
4. Indian languages Many students write their answers in Hindi and other Indian languages. The on-device models support many languages, so we'll add them one at a time, only after testing accuracy for each.
5. Board and curriculum mapping Map concepts directly to CBSE, ICSE and state board syllabi, so insights and reteaching plans line up with what each class is required to cover.
6. Teacher-approved reports for parents Let teachers share each student's strengths and areas to improve with parents in plain language. Nothing is shared without the teacher's review.
7. Following students across subjects and years Let a student's skill patterns carry across teachers and school years, with the school's consent and only as counts, never answers, so support continues when a student moves to a new class.
8. Classroom tool integration Import class lists and export marks and lesson plans to tools schools already use, like Google Classroom, so RedPen fits into existing workflows.
The goal stays the same: every student understood, not just scored.
Built With
- antigravity
- css
- firebase
- firebase-ai-logic
- gemini
- gemini-nano
- google-cloud
- html
- javascript
- python
- typescript