Delivered remotely for a business based in Dubai, United Arab Emirates. Names withheld by agreement.
Project Overview
Academic assessment authoring operates under unforgiving structural constraints. An exam paper cannot simply contain "ten good questions"; it must satisfy exact mark distributions, cover prescribed syllabus chapters proportionally, span recall through analytical synthesis on Bloom's taxonomy, avoid repeating recent past papers, and include an unambiguous marking scheme for graders. Generic prompt boxes fail immediately on this workload because unconstrained language models invent out-of-syllabus facts, miscount marks, and repeat textbook clichés across parallel exam variants.
We engineered an AI question paper generator on Python, FastAPI, React, and PostgreSQL with pgvector. The platform pairs deterministic curriculum blueprint planning with syllabus-grounded item generation, inline LaTeX review tools, and automated assembly of print-ready papers and teacher answer keys.
Business Bottleneck
Academic departments drafting midterms, standardized mocks, and multi-set final exams faced chronic bottlenecks:
- Manual blueprint balancing: Teachers spent hours juggling spreadsheets to ensure every unit weight, difficulty tier, and cognitive skill quota summed to exact exam totals.
- Out-of-syllabus hallucinations: Unanchored AI drafts routinely tested notation, formulas, or theorems absent from the institution's adopted curriculum edition.
- Parallel-set leakage and repetition: Creating Set A, Set B, and makeup exams with equivalent difficulty but distinct question stems often devolved into trivial number swaps.
- Broken formatting before print: Copying equations and multi-part sub-questions between chat tools and word processors mangled LaTeX notation and pagination.
Architectural Strategy
We designed the system as a blueprint-first constraint pipeline wrapped around pgvector syllabus retrieval and human moderation. Rather than asking an LLM to write an entire exam paper in one shot, faculty configure a formal blueprint object in React—specifying sections, mark weights, question formats (MCQ, short structured, long analytical), chapter scopes, and Bloom levels.
FastAPI validates blueprint arithmetic deterministically, breaks the specification into discrete item slots, and queues parallel generation jobs onto Redis. Each slot worker queries PostgreSQL/pgvector for relevant approved curriculum excerpts, invokes structured JSON generation validated via Pydantic, checks semantic novelty against past-paper embeddings, and streams ready items back to the React workspace for teacher refinement and moderator lock.
Core Capabilities
- Syllabus Ingestion & Unit Tagging: Parses PDFs and structured curriculum guides into hierarchy-aware chunks preserving headings, formulas, and learning objectives in pgvector.
- Formal Blueprint & Parallel-Set Planner: Enforces exact mark sums, section choices, difficulty ratios, and multi-variant parity before generation starts.
- Grounded Item & Rubric Synthesis: Produces question stems, plausible distractors with misconception notes, step-by-step worked solutions, and point-by-point marking keys simultaneously.
- Semantic Novelty & Past-Paper Guard: Flags or regenerates candidate questions that closely resemble prior terms or sibling exam sets.
- Dual Print Assembly: Compiles locked drafts into clean, institution-branded student question papers alongside separate moderator-only marking guides.
Technical Architecture
Uploaded syllabus documents flow through Python extraction workers that preserve mathematical blocks and section metadata before computing embeddings stored in PostgreSQL via pgvector. When an educator launches a blueprint job, FastAPI stores the immutable blueprint specification, reserves slot records, and dispatches parallel tasks to Redis-backed ARQ workers.
Flow: React Blueprint Editor → FastAPI Validator & Slot Planner → PostgreSQL + pgvector (Syllabus Chunks & History) → Redis / ARQ Workers → Structured LLM + Similarity Guard → React Moderation Studio → PDF / Answer Key Compiler
Each worker retrieves top matching curriculum chunks scoped strictly to the blueprint's unit filters, constructs a slot prompt enforcing exact mark counts and Bloom taxonomy verbs, parses the JSON response through strict Pydantic validators, and verifies that LaTeX delimiters compile cleanly. React subscribes via SSE/polling to display candidate items progressively inside a split-pane editor with instant KaTeX rendering.
Technology Stack
| Category | Technology detail |
|---|---|
| Authoring Frontend | React + TypeScript with live KaTeX preview and blueprint builder |
| Backend Orchestrator | Python + FastAPI with Pydantic structured output validation |
| Database & Vector Store | PostgreSQL + pgvector indexing syllabus chunks and historical item embeddings |
| Async Job Queue | Redis + ARQ workers running batch item generation and PDF compilation |
| Document Ingestion | Python syllabus parser preserving chapter hierarchy, diagrams, and equations |
| Print & Typesetting Engine | WeasyPrint / LaTeX compilation pipeline generating locked paper & key PDFs |
| Deduplication Guard | Cosine-similarity checks against pgvector history to prevent repeat questions |
| Access & Exam Security | Role-isolated draft vaults with watermarking and audit trails |
Engineering Trade-offs & Solutions
| Engineering Challenge | Solution & Trade-off |
|---|---|
| Preventing whole-paper generation from dropping marks or ignoring sections | Decomposed blueprints into per-slot FastAPI/ARQ jobs with Pydantic mark-sum verification; increases total LLM calls per paper slightly while guaranteeing structural accuracy. |
| Stopping repeat questions across Set A/B and previous semesters | Ran pgvector cosine-similarity checks on candidate stems before persistence; adds minor embedding latency per item in exchange for genuine variant diversity. |
| Rendering complex STEM equations reliably in both browser and PDF | Standardized internal item storage on Markdown + LaTeX, previewing via KaTeX in React and typesetting server-side for print; constrains arbitrary freeform layout tweaks while eliminating broken math exports. |
| Managing slow document parsing and PDF compilation bursts | Isolated heavy PDF ingestion and WeasyPrint/LaTeX builds onto dedicated ARQ workers queued in Redis so interactive React authoring stays responsive. |
Security & Reliability
Unpublished exam papers require strict pre-test confidentiality. Draft papers, blueprint allocations, and answer keys are scoped by department and exam-cycle permissions inside FastAPI so teachers outside an assigned subject team cannot view upcoming assessments. Approved final PDFs carry optional user/batch watermarks and download audit logs stored in PostgreSQL.
To protect upstream model reliability, worker jobs apply strict JSON schema retries, bounded token budgets per slot, and deterministic fallback prompts if an initial draft fails mark-count or LaTeX syntax checks—ensuring incomplete slots surface clearly for manual authoring rather than corrupting an entire exam draft.
Performance & Scale
Splitting exam generation into concurrent slot tasks over Redis/ARQ drastically cuts wall-clock wait times during peak pre-exam weeks when multiple departments assemble papers simultaneously. HNSW indexes on pgvector keep syllabus retrieval and cross-term duplicate checks fast even as institutional question banks grow across years.
In the browser, React caches parsed KaTeX fragments per item card so dragging questions between sections, swapping alternatives, or toggling answer-key previews feels instantaneous without re-typesetting unchanged blocks.
Operational Outcomes
Combining formal blueprint validation, pgvector curriculum grounding, and React moderation tooling turned exam authoring into a repeatable institutional workflow:
- Strict syllabus fidelity: Every generated question traces back to indexed textbook sections and explicit learning objectives reviewed by subject faculty.
- Consistent assessment balance: Automated mark arithmetic and Bloom taxonomy quotas ensure multi-section papers and parallel variants maintain comparable rigor.
- Faster moderation cycles: Side-by-side stems, distractors, and step-by-step marking keys let department heads review and approve papers cleanly before print lock.
- Print-ready accuracy: Standardized LaTeX-to-PDF compilation removed last-minute equation formatting defects across exam papers and grading guides.