-
-
Line 2 proven wrong by SymPy, boxed and underlined in red on the photo (sample sheet, live app).
-
Redline: finds the exact line where your math went wrong. Won't give you the answer.
-
"Is this what you wrote?" Claude reads each line with a numbered box; you confirm before anything is judged.
-
Hint 3: a worked example with different numbers. Every hint passes a code answer guard.
-
The learner fixes line 2 and finishes: all 5 steps verified.
-
Verified diagnosis on another sample, with the nudge in Hindi (also Marathi and Spanish).
-
Measured, not claimed: 100% of 157 seeded errors located, 0% false alarms, 91.7% named (live /how-it-works).
-
Instructor dashboard: anonymous class misconceptions and what to re-teach (author-generated demo class).
Inspiration
AI made getting answers free and made learning optional.
In a 2025 field experiment with about 1,000 high-school students, those who practised with unrestricted GPT-4 went on to score 17% lower on the exam without it than students who never had it (Bastani et al., Generative AI without guardrails can harm learning, PNAS 2025). And the mistakes that sink students are rarely conceptual mysteries. They're procedural: a sign dropped, a bracket half-distributed. Those errors persist from College Algebra all the way into Calculus II (Cangelosi et al., 2013).
When a learner checks their work today, they get one of two things: "wrong" (no location, no reason) or the full solution (no learning). We wanted the thing a good teacher does with a red pen: circle the exact line where the reasoning broke, say why, and hand the pen back.
What it does
Redline reads a photo of your handwritten algebra and finds the first line that doesn't follow from the one before it. Then it refuses to give you the answer, and teaches you instead.
- Read. Snap a photo (or type your steps). Claude transcribes each line into a strict math grammar and returns a box for where it sits on the page. Redline snaps every box to the actual ink row.
- Confirm. "Is this what you wrote?" You fix any misread line, so Redline never blames you for something you didn't write.
- Prove. SymPy compares the solution sets of every consecutive pair of lines. The first line that changes the solution set is the error, and it gets boxed and underlined in red, right on your photo. The AI never decides correctness.
- Name. Ten common misconceptions are written as executable rewrite rules. If applying one to your previous line reproduces your line exactly, the diagnosis is marked Verified: it's a proof, not a guess. Only if no rule matches does Claude offer a clearly labelled AI hypothesis.
- Coach. Three hints, each giving a little more: a nudge, then the rule, then a worked example with different numbers. Every hint passes a deterministic answer guard before you see it.
- Fix and re-verify. Retype the line; Redline re-checks every step until "All steps verified."
- Practise. Two fresh problems built to trigger the same misconception, with answers checked by SymPy.
- Teach the class. Instructors create a class code; learners can share the type of mistake anonymously (no names, no photos, no work); the dashboard shows what's most common and what's worth re-teaching.
Hints come in English, Hindi, Marathi and Spanish. It works from a phone photo, with no accounts and no stored photos.
How we built it
The AI reads and explains. The math engine judges. Code enforces the teaching rules.
That split is the whole design. Every decision that has to be right is made by deterministic code; the language model is used only where perception and language are needed.
- Engine (Python, FastAPI): one service owns all math and AI logic.
safe_parse.pyis the security boundary. It whitelists characters, caps length, exponents, numbers and nesting, and only then calls SymPy's parser with a minimal namespace. Model output goes through the same gate, which makes prompt injection inside a photo harmless.verifier.pycompares solution sets over ℝ withsolveset, with an expression-equivalence check and a numeric fallback. A smaller set means a lost root (dividing by x, a missing ±); a bigger set means an extraneous root (squaring both sides). Each step runs under a 3-second timeout.malrules.pyapplies ten buggy rewrite rules (e.g.−k(a+b) → −ka + kb) to the previous line and compares the result with the learner's line. The idea comes from MalruleLib (arXiv 2601.03217).guard.pyrejects any hint that contains an equation with the problem's solution set, an "x is 4"-style phrase, or the corrected term. A leaking draft is regenerated once, then replaced by a unit-tested built-in hint. The correct answer is never sent to the browser or to the model.boxes.pysnaps the model's approximate line boxes to ink rows using a row projection in Pillow, so the red underline lands on the handwriting.ai.pyis the only module that calls Anthropic Claude, always with structured outputs, for three narrow jobs: transcription with line boxes, labelled hypotheses, and hint wording.
- Web (React, TypeScript, Vite, Tailwind, KaTeX): capture → review → results → hints → fix → practice, plus an instructor dashboard. Photos are downscaled in the browser before upload.
- Data: optional Postgres (Neon) for class mode, storing only
{class code, misconception id, topic, time}. - Deploy: Vercel Services: the Vite app as the frontend, the FastAPI engine as a Python function behind
/api/*. One Dockerfile also runs everything anywhere. - Resilience: with no key, no quota or no network, typed steps, verification and built-in hints all keep working, and the UI says so.
We measured it instead of claiming it
An evaluation harness (eval/run.py) takes 15 correct worked solutions and injects every applicable misconception at every step, producing 157 seeded errors. The results are published live on the app's /how-it-works page, failures included:
| Measure | Result | Cases |
|---|---|---|
| Wrong line found exactly | 100% | 157 |
| False alarms on correct solutions | 0% | 15 |
| Misconception named as labelled | 91.7% | 157 |
| Hints leaking the answer before the guard (live) | 10% | 20 |
| Hints leaking the answer after the guard (live) | 0% | 20 |
| Sample sheets, right line + misconception end to end (live) | 3 / 3 | 3 |
That 10% → 0% row is the reason the guard exists: the model is told never to reveal the answer and is never given the answer, and it still worked it out in 2 of 20 drafts. The guard caught both.
Challenges we ran into
- SymPy's
parse_exprisevalunderneath. Passing learner (or model) text straight in would let__import__('os')run. We built a whitelist gate with hard caps before anything reaches the parser. - SymPy quietly "fixes" mistakes. Even with
evaluate=False,-(x - 4)was expanded to4 - x, which hid exactly the sign errors we needed to see. We had to preserve the learner's structure to diagnose how they went wrong. - Equal expressions vs. equal solution sets.
2x = 16andx = 8aren't equal expressions, but they're a valid step. Getting this right, including lost and extraneous roots, was the core of the verifier. - Ambiguous diagnoses. One changed number can be explained by several rules, so rules need a priority order, and "arithmetic slip" had to be strict enough not to swallow real misconceptions.
- Guard false positives. The learner's own bracket can look like the corrected term, so the guard has to tell quoting the learner apart from giving the answer.
- Red pen on a photo. Model bounding boxes are approximate, so we snap them to real ink rows; otherwise the underline floats half a line off.
Accomplishments that we're proud of
- 100% of seeded errors found on the exact line, with 0% false alarms, and 91.7% of misconceptions named as labelled, all published as measured, failures included.
- A verified diagnosis that is a proof: Redline reproduces your exact line by applying the mistake in code.
- 0% of hints leaked the answer after the guard, measured live, against a 10% raw leak rate.
- The evaluation paid for itself: it found two real bugs the hand-written tests missed (a step collapsing to
3x = 3xwas only a warning, and the "divided by x" rule fired whenever a side was 0). Fixing them moved localisation from 98.1% to 100%. - A full, working product: phone photo to verified diagnosis to guarded hints to re-check to practice, in four languages, live on the web.
What we learned
- Prompts aren't guarantees. Code guards are. Measuring the pre-guard leak rate is what made the guard's value visible.
- A library's normalisation is great for checking correctness and terrible for diagnosing mistakes.
- Make misconceptions executable. Asking an LLM "what did the student do wrong?" gives a guess. Applying buggy rules and checking which one reproduces the line gives a proof.
- Reading the API terms changed our audience. Provider terms shaped who the product can safely serve, which is why Redline is scoped to adult learners (18+) behind an in-app gate for now.
What's next for Redline
- Real-photo evaluation: a set of real handwritten photos, with published photo accuracy (today's sample sheets are rendered in handwriting fonts, not photographed).
- A safe under-18 version: a provider and safeguards suitable for high-school learners, the group the PNAS study is about.
- More algebra: inequalities, systems and rational equations.
- A classroom pilot with an instructor, using the anonymous class dashboard.
Responsible AI and honesty notes
- In-product AI: Anthropic Claude reads handwriting, suggests clearly labelled hypotheses, and words hints. It never decides correctness and is never given the answer.
- Privacy: photos are processed in memory and never stored; no accounts; class mode stores only a code, a mistake type and a time. For learners 18+.
- Built with AI assistance: Claude Code was used as a coding assistant (see
AI_DISCLOSURE.mdin the repo). - Caveat: the synthetic error set is generated by the same rule family the engine uses, so it measures consistency rather than coverage of real student errors. The demo class on the instructor dashboard is author-generated data.
- Pre-existing work: none. Built Nov 25–29, 2026.
Built With
- anthropic
- claude
- docker
- fastapi
- katex
- neon
- pillow
- postgresql
- pydantic
- python
- react
- sympy
- tailwindcss
- typescript
- vercel
- vite