Inspiration

Matching patients with complex medical histories to clinical trials is traditionally a manual, time-consuming process for healthcare providers. Doctors often have to scan dense Electronic Health Record (EHR) notes against pages of inclusion and exclusion criteria. We were inspired to build a tool that uses generative AI to instantly analyze clinical notes, matching patients with active clinical trials accurately and transparently.

What it does

The AI Clinical Trial Matcher is an end-to-end web application that:

  1. Takes a target medical condition and unstructured EHR patient notes as input.
  2. Queries the ClinicalTrials.gov REST API v2 to retrieve active recruiting studies.
  3. Uses Google Gemini 2.5 Flash to evaluate patient notes against each study's eligibility criteria.
  4. Returns an instant evaluation featuring color-coded match status (ELIGIBLE, INELIGIBLE, or MAYBE), a confidence score (0–100%), detailed clinical reasoning, and itemized bullet points for met inclusion criteria and exclusion violations.

How we built it

  • Backend: Built using FastAPI to orchestrate requests and expose clean endpoints.
  • API Integration: Integrated ClinicalTrials.gov REST API v2 to fetch live, up-to-date trial metadata.
  • LLM & Structured Output: Used the official Google GenAI SDK (google-genai) with gemini-2.5-flash. We enforced strict output structure using Pydantic schemas (response_schema) and response_mime_type="application/json" to guarantee reliable JSON responses without markdown parsing errors.
  • Frontend: Built an interactive dashboard using Streamlit for real-time visualization of matching results.

Challenges we faced

  • Structured Output Enforcement: Ensuring the LLM consistently returns strictly typed JSON matching our schema required tuning the prompt and utilizing Gemini's structured output settings alongside text cleaning logic.
  • API Rate Limits: Handling per-minute quota limits on AI API calls during repeated matching runs was resolved by optimizing pipeline calls and pacing requests.
  • Criteria Parsing: Clinical trial eligibility text can be ambiguous; structuring the prompt to force strict analysis of age, organ function, and cancer staging helped eliminate false positive matches.

Accomplishments that we're proud of

  • Successfully built a fully functional end-to-end prototype combining live external clinical trial data with generative AI reasoning.
  • Eliminated model hallucinations by forcing Gemini to output structured Pydantic data models for clear clinical decision support.
  • Developed an intuitive Streamlit UI that makes complex medical criteria instantly digestible with clear visual badges and reasoning breakdowns.

What we learned

  • How to leverage Gemini's structured output capabilities (response_schema) to build production-grade AI microservices.
  • How to query and parse complex medical APIs like ClinicalTrials.gov.
  • Best practices for designing AI tools tailored for healthcare workflows where explainability is critical.

What's next

  • Multi-file EHR Uploads: Support PDF/FHIR data ingestion directly into the patient pipeline.
  • Geographic Filtering: Add location-based trial filtering so patients are matched with trials near their zip code.
  • Batch Processing: Allow doctors to batch-process multiple patient profiles simultaneously. ## Accomplishments that we're proud of

Built With

  • fastapi
  • gemini-api
  • google-gemini
  • pydantic
  • python
  • streamlit
Share this project:

Updates

Submission history