Document Q&A API: answer questions about a PDF
Your first deliverable: a service someone else can run, that takes a PDF and answers questions about it.
The brief
A small legal team keeps asking the same questions of the same contracts. They want to upload a PDF and ask plain questions, without pasting pages into a chat window.
What you will build
- An endpoint that accepts a PDF upload
- An endpoint that takes a question and returns an answer
- A typed response with the answer and the page it came from
- A README that gets a stranger running in five minutes
Requirements
| Requirement | Done when |
|---|---|
| Upload | A PDF up to 20 pages is accepted and its text extracted |
| Answer | Questions return a typed object, never free text you have to parse |
| Source | Each answer names the page it relied on |
| Errors | A scanned PDF with no text returns a clear error, not a crash |
| Tests | Upload, answer and error paths have tests |
| Run it | One command starts it, in a container |
What to learn it from
- Python for AI: JSON files, Pydantic, async and pytest
- APIs for AI: FastAPI, model API calls and tests
- LLM Fundamentals: prompts, structured output and context windows
Milestones
- Extract text from a PDF and print it
- Answer one hard-coded question from that text
- Wrap it in two API endpoints
- Return a typed answer with the page number
- Add tests and a container
- Write the README and ask someone else to run it
How it is judged
A stranger clones the repository, runs one command, uploads a PDF and gets a correct answer with a page reference. Nothing else counts.
Stretch goals
- Handle documents longer than the context window
- Stream the answer as it is written
- Cache answers to repeated questions
Before you call it done
Worth remembering
- It runs from the README alone
- Every answer carries its source page
- The failure cases have tests
Every expert started right here.