ProcureGuard
An early experiment, not shipped and not maintained. A FastAPI service that detects vendor price drift and contract non-compliance, ranks suppliers from CSV input, and generates business-readable explanations using Gemini and the OpenAI API.
- Status
- Experiment
- Commits
- 32
- API handlers
- 7
- Docker stages
- 2
- Licence
- MIT
Why I built it
Procurement data is a good testbed for a question I keep returning to: when a system flags something, what evidence does a human need in order to act on it? A drift score on its own gets ignored. A drift score with a generated explanation and a ranked alternative is a decision.
Architecture
- FastAPI application exposing seven handlers: health, detection start, detection status, leaks, traffic simulation, vendor ranking, and ranking explanation.
- Asynchronous detection dispatch using FastAPI BackgroundTasks with an in-memory task store, polled by a status endpoint.
- Pydantic schemas for every request and response contract.
- Gemini 1.5 Flash for detection reasoning; the OpenAI API for vendor ranking explanations.
- A two-stage Docker build: node:18-slim compiles the React frontend, python:3.11-slim serves it from the API. A second Dockerfile runs the service as a non-root user.
- pytest suite and a GitHub Actions workflow.
Engineering decisions
Async dispatch with an in-memory task store
Detection was too slow to answer inside a request, so POST starts a job and GET polls its status. Two of the seven endpoints exist only to support this. The store is in-memory, which means a process restart loses every in-flight task. That is acceptable for a single-instance prototype and unacceptable the moment there is more than one replica. Naming the limit is more useful than pretending it is a queue.
Two LLMs for two different jobs
Gemini 1.5 Flash handles detection reasoning where latency and cost matter more than prose quality. The OpenAI API generates the ranking explanations a human actually reads. Splitting them was cheaper than making one model do both well.
Deleting the duplicate implementation
For months the repository contained a second, parallel implementation under a separate directory that nothing in the live API referenced. It made the project look larger and made it considerably harder to read. Removing it was the single best commit in the repo.
What I learned
- A prototype that names its own failure boundary reads as more competent than one that claims none.
- Two implementations of the same idea in one repository is not optionality, it is confusion.
- The licence file matters. This repo carried a content licence over source code until I actually read it.