Physical Exam: Question Paper Metadata Autofill¶
When a trainer creates a physical exam, this feature reads the question paper's first-page header on upload and pre-fills the form fields that are already printed on the paper: subject, test name, max marks, date, exam time. Anything it cannot find is left blank for manual entry, so the trainer reviews instead of retyping.
How it works¶
Question paper upload (page 1 header)
│
▼
parse-question-paper ──► suggested_fields ──► pre-fill form inputs (title, marks, date, duration)
│ extracted_metadata ─► stored as JSON on the exam (faculty, semester, …)
▼
attachment_id ──► reused at exam creation (no second upload)
In the create wizard's DETAILS step, the question paper upload sits at the top and triggers extraction immediately. parse-question-paper runs OCR via the existing doc-intelligence extract-document-text, then the in-repo LLM gateway parses the header into structured fields. The four fields with form inputs (title, total marks, date, duration) pre-fill, each with a small auto-filled marker, and a banner reads "We filled in N fields from your question paper, please review." The marker clears on edit. Fields the form has no input for (faculty, semester, department, institution, subject code, raw exam time) are preserved as JSON in the physical_exams.extracted_metadata column rather than discarded.
The exam is still created at the end of the step, reusing the already-uploaded attachment via question_paper_attachment_id on the create payload. Question extraction (the existing extract-questions step) still runs after creation, unchanged.
Invariant: extraction never blocks creation. On failure the endpoint still returns attachment_id and found: false, the file uploads, and the form stays manual.
Edge cases:
- Non-standard paper or nothing found:
found: false, all suggestions null, no banner, manual entry as today. - Partial extraction: only the found fields pre-fill; the rest stay blank.
- Edit mode: autofill does not run; existing behavior unchanged.
Endpoints¶
| Method | Endpoint | Purpose |
|---|---|---|
| POST | /physical-exams/parse-question-paper |
Upload paper, return suggested fields + raw metadata + attachment id |
| POST | /physical-exams |
Create, accepts question_paper_attachment_id, extracted_metadata |
Where it lives¶
Route: the physical-exam create wizard (CreatePhysicalExamPage).
apps/backend/src/api/v1/physical_exam.py:parse-question-paperroute; create linkageapps/backend/src/models/physical_exam.py:extracted_metadatacolumnapps/web/src/pages/shared/CreatePhysicalExamPage/components/DetailsStep.tsx: upload-first flowapps/web/src/services/physicalExam/:parseQuestionPaperclient