Skip to content

Data Model: API Schemas

These records flow through a single query: from the search loop, through summary generation, into the API response returned to the frontend. For the fixed corpus records they draw from (Condition, Paper), see Data Model: Corpus Records.

Overview

  1. When a query arrives, the search loop retrieves papers and produces LoopTraceEntry records (one per iteration).
  2. Retrieved papers are passed to summary generation, which produces a SourcedSummary.
  3. The SourcedSummary is mapped to a QueryResponse (along with trace and context data), which is returned to the frontend.
  4. The frontend displays the summary, citations, differential diagnoses, and loop trace to the user.

Record Types

The search loop runs up to two iterations to retrieve papers relevant to a given query. Each iteration produces a trace entry describing what was retrieved and whether it passed the relevance check.

LoopTraceEntry

One LoopTraceEntry captures the result of a single search loop iteration. Multiple entries (typically up to 2) appear together in the final API response, allowing the frontend to visualize the retrieval process.

FieldTypeDescription
iterationintegerIteration number (1-indexed)
retrieved_pmidslist of stringsPMIDs retrieved in this iteration before relevance filtering
relevantbooleanWhether the LLM relevance check confirmed this iteration's papers matched the query
confidencefloatRelevance confidence score (0.0 to 1.0); used to flag low-confidence summaries
notestringPlain-text note describing the iteration's outcome or strategy
relevant_countintegerNumber of papers deemed relevant by the relevance check (defaults to 0)
total_countintegerTotal number of papers in this iteration before relevance filtering (defaults to 0)

Once the search loop completes, the retrieved papers are fed into summary generation, which produces a SourcedSummary. This internal record is then shaped into the API response schemas that the frontend consumes.

SourcedSummary (internal)

A SourcedSummary is generated from the list of papers the search loop returned. It serves as the internal interchange point between summary generation and the API handler, and its fields map directly onto QueryResponse fields.

FieldTypeDescription
textstringThe final summary text, including any prepended disclaimers (low-confidence, sparse coverage)
citationslist of dictsList of citations in order; each has marker ("[1]", "[2]", ...), pmid, and title. Positionally indexed to the papers list: citations[i] corresponds to papers[i]
raw_textstringThe summary text before any disclaimer was prepended (defaults to empty string)
degradedbooleanWhether the LLM call failed or timed out, meaning no usable summary was produced
original_tokensintegerToken count of the raw abstracts before compression (defaults to 0)
compressed_tokensintegerToken count after Paritok compression (defaults to 0)
imaging_findingsstring or nullBrief description of imaging findings and uptake pattern, extracted from the LLM's JSON response (null if not stated in abstracts)
teaching_pointstring or nullClosing clinical insight (null if not included by the LLM; the prompt also instructs the LLM to null this when imaging_findings is null, but that pairing isn't enforced in code)
differential_candidateslist of dictsDifferential diagnoses extracted from the LLM's JSON response; each has condition_name and marker (the citation it references). Limited to 0-3 items (defaults to empty)

QueryResponse (API response)

QueryResponse is the top-level Pydantic model returned by POST /query. It includes the summary, citations, trace, and metadata about the search and generation process.

FieldTypeDescription
summary_textstringThe final summary text (matches SourcedSummary.text)
citationslist of CitationOutNumbered citations referenced in the summary
tracelist of TraceEntryOutSearch loop iteration records, allowing the frontend to show retrieval flow
low_confidencebooleanWhether the relevance check's confidence was below the passing threshold; summarization proceeded anyway
degradedbooleanWhether the LLM summarization call failed, meaning the summary is empty and unreliable
no_matchbooleanWhether no papers matched the query at all; defaults to false
suggested_conditionslist of SuggestedConditionOutAlternative conditions to try when no_match is true; defaults to empty
flagged_claimslist of dictsPer-claim citation verification results for every cited sentence, including ones marked supported; used by the frontend to surface unsupported/uncited/invalid-marker claims. Defaults to empty
case_contextCaseContextOut or nullContextual information about the condition the papers address (null if degraded)
differentiallist of DifferentialItemOutDifferential diagnoses with citations, extracted from the summary; defaults to empty

CitationOut

Represents one citation in the summary.

FieldTypeDescription
markerstringCitation marker, e.g. "[1]", "[2]"
pmidstringPubMed identifier
titlestringPaper title
conditionstringCondition name this paper belongs to

TraceEntryOut

Mirrors LoopTraceEntry 1:1 at the API boundary.

FieldTypeDescription
iterationintegerIteration number (1-indexed)
retrieved_pmidslist of stringsPMIDs retrieved in this iteration
relevantbooleanWhether this iteration passed the relevance check
confidencefloatRelevance confidence score
notestringPlain-text note on the iteration's outcome
relevant_countintegerNumber of papers deemed relevant (defaults to 0)
total_countintegerTotal papers in this iteration before filtering (defaults to 0)

SuggestedConditionOut

Returned in suggested_conditions when the search failed entirely, offering nearby conditions in the corpus to try instead.

FieldTypeDescription
namestringCondition name
paper_countintegerNumber of papers in the corpus for this condition

CaseContextOut

Clinical context extracted from the best-matching paper's condition record. Populated when summarization succeeds.

FieldTypeDescription
condition_namestringThe condition name
raritystring"rare" or "common"
region_literaturestringPlain-language description of typical imaging regions
atlas_labelstringAtlas region labels for the 3D viewer
corpus_paper_countintegerNumber of papers in the corpus for this condition
imaging_findingsstring or nullImaging findings summary (matches SourcedSummary.imaging_findings)
teaching_pointstring or nullClinical teaching point (matches SourcedSummary.teaching_point)

DifferentialItemOut

A differential diagnosis extracted from the summary, with the citation supporting it.

FieldTypeDescription
condition_namestringAlternate condition name
markerstringCitation marker, e.g. "[2]"
pmidstringPubMed identifier of the supporting paper