AeroDx Ships a Medical AI That Admits It's Fake
Inside a lung-disease triage API where the model returns random diagnoses, every result says so in writing, and the swap-in seam is the entire point.
- AeroDx fabricates lung-disease diagnoses on purpose, then stamps every result with model_version='stub-v0.1' and a recommendation string that says the result is fake.
- The honesty is injected into the data payload, not the logs, so a downstream consumer cannot mistake a random label for a real one without actively ignoring an explicit field.
- Three marked files carry the entire swap-in contract: ModelLoader.load(), MLService.predict(), and chat_service._generate_reply(), each replaceable without touching routes, schemas, or persistence.
- Pydantic schemas are the single source of truth, enforcing bounds and enums at every boundary so the model can be dropped in without reshaping the API.
The Diagnosis That Snitches on Itself
Run a CT scan through AeroDx and you get a result. A label. A confidence of 0.94. A probability vector that sums to 1.0 and looks exactly like softmax output. Everything a frontend needs to render a believable clinical triage screen.
Then you read the payload and the illusion collapses. The result carries model_version="stub-v0.1". Its recommendation field reads, verbatim: "This is a STUB result. Integrate real model before clinical use." The label was drawn with random.choice(list(DiseaseLabel)). The confidence came from a uniform draw between 0.70 and 0.99.
The system is lying, and it wants you to know. That is the whole idea.
Most prototypes bury their placeholders. A hardcoded return "Normal" hides in a corner of the codebase and leaks into a demo the moment someone forgets. AeroDx takes the opposite approach: the placeholder status lives inside the response object, at the same level as the diagnosis it is qualifying. In a regulated domain, that is a design discipline worth studying.
Four Endpoints, One Missing Brain
The main.py docstring lays out the intended workflow in four steps. Upload a scan. Analyze it. Ask questions about the result. Download a PDF report. Each step maps to a real endpoint, and each endpoint works end to end.
The layering is clean. routes handles HTTP and almost nothing else. services holds the behavior. models/schemas.py defines the shared vocabulary that both layers speak. When a route needs a scan, it asks scan_service. When analysis is required, scan_service asks ml_service. Every dependency points one direction.
That structure is what makes the missing brain survivable. Because predict() returns a fully typed AnalysisResult, nothing upstream cares whether the object came from a neural network or a coin flip. The schema is the contract, and the stub honors it.
The Seam Is the Product
Three files are marked for replacement, each with explicit instructions in its module docstring. ModelLoader.load() for loading weights. MLService.predict() for inference. chat_service._generate_reply() for wiring in an LLM. The docstring is not a comment; it is a handoff document.
The claim that "everything else needs zero changes" is credible because predict() returns a typed object, not a dict, not a tuple, not a loose bag of primitives. Swap the body of the function and every downstream consumer keeps working, from the chat router to the PDF generator.
But the most interesting part of the seam is what does not get replaced. The result stamp, the version field, the recommendation string: those survive the swap. They belong to the contract, not the stub. A real model inherits the honesty machinery even after it stops needing it.
Pydantic as the Single Source of Truth
The schemas do work the model would otherwise have to do. Bounds, enums, and length limits are enforced at every boundary, so malformed data cannot enter the pipeline regardless of what produces it.
class DiseaseLabel(str, Enum):
NORMAL = "Normal"
COVID19 = "COVID-19"
PNEUMONIA = "Pneumonia"
TUBERCULOSIS = "Tuberculosis"
LUNG_CANCER = "Lung Cancer"
PULMONARY_FIBROSIS = "Pulmonary Fibrosis"
UNKNOWN = "Unknown"
class Finding(BaseModel):
region: str
description: str
confidence: float = Field(..., ge=0.0, le=1.0)
class AnalysisResult(BaseModel):
predicted_label: DiseaseLabel
confidence: float = Field(..., ge=0.0, le=1.0)
severity: SeverityLevel
findings: list[Finding]
recommendations: str
model_version: str
raw_probabilities: Optional[list[float]] = None
class ChatRequest(BaseModel):
message: str = Field(..., min_length=1, max_length=4000)
scan_id: Optional[str] = None
Two details stand out. The six-label taxonomy is broader than the sibling covid_detector_package suggests, and the UNKNOWN label is a sensible escape hatch for a model that has not been trained yet. And the 4000-character cap on chat messages is a genuine defense against prompt-stuffing if an LLM is later wired into _generate_reply(). That is the kind of constraint you only add if you are planning ahead.
The confidence field is bounded to [0.0, 1.0] on every object that carries one. So even the random draw from [0.70, 0.99] is guaranteed to land inside the range a real model would produce. The stub is not just random; it is random within the shape of a valid result.
Where the Scaffold Leaks
The scaffold is honest about its own gaps. The scan_service stores live in module-level dictionaries with an inline comment that reads, in effect, replace with SQLAlchemy, MongoDB, or Redis in production. Restart the process and every scan vanishes.
- No authentication.
list_scansreturns every analysis in memory with no pagination, no ownership filter, and no access control. In a medical context that is a data-exposure concern. - Upload validated after full read.
save_scancallsawait file.read()before checking size, so a 5 GB upload is buffered into RAM before rejection. - The .nii.gz bug.
ALLOWED_EXTENSIONSlists.nii.gz, butPath(filename).suffixreturns only.gzfor a compound extension, so NIfTI-compressed uploads are rejected with a 415. - DEBUG=True by default. Production deployments must remember to override it, or debug logging on a medical service could leak request details.
- Deprecated APIs.
datetime.utcnow()is deprecated in Python 3.12, andapp.on_eventlifecycle hooks have been superseded bylifespan. - Dead code.
ReportResponseis defined in schemas but the reports endpoint returns raw PDF bytes instead. Thehistoryparameter in_generate_replyis accepted and never read.
None of these are failures. They are the expected shape of a proof of concept, and the code comments say so. The scaffold knows it is a scaffold.
What a Stub-First API Buys You
| AeroDx (stub stage) | Typical demo scaffold | Production medical AI | |
|---|---|---|---|
| Inference | Random labels, honest version stamp | Random or hardcoded, unlabeled | Validated model, versioned weights |
| Persistence | In-memory dicts, lost on restart | Often none | Database with audit log |
| Auth | None | None | Required, role-scoped |
| Audit trail | PDF metadata table only | Usually absent | Full request and model provenance |
| Placeholder honesty | Explicit in the result payload | Implicit | Not applicable |
AeroDx loses to a production system on every operational axis. It loses to a typical demo scaffold on nothing, and it beats both alternatives on exactly one thing: it never lets you forget the model is fake. That single property is what makes the rest of the scaffold safe to ship to a frontend team before the weights exist.
The Next Commit
The sibling directory covid_detector_package already contains a full training pipeline: prepare_dataset.py, train.py, covid_model.py, and predict.py, with its own README and requirements. The backend loader never references it. ML_MODELS_DIR expects a single artifact that nothing currently parses.
So the project sits at a specific and familiar place: a trained-or-trainable model exists in one corner of the repository, a designed socket exists in another, and the two have not been joined. The next commit is the handoff between a data scientist and a backend engineer. Everything the backend needs is already in place. The only question is whether the model file that lands in /ml_models/ arrives before someone forgets why the stub was honest in the first place.





