# samer-4/priorauth-rag architecture

> Architecture diagram of the GitHub repository samer-4/priorauth-rag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/samer-4/priorauth-rag
- Repository: https://github.com/samer-4/priorauth-rag

## Overview

This repository is an active-development prior-authorization appeal builder. Its principal workflow takes a denial letter and clinical notes, extracts structured denial details, selects payer policy criteria, finds and evaluates supporting evidence, generates a structured appeal draft, and checks the draft for grounding and consistency. The graph focuses on the implemented pipeline; the README’s planned RAG, agent orchestration, and deployment capabilities are not shown as current components. Connections are based on the README and sampled source, including the case runner; other runtime details were not inspected.

Main entry points: [`src/baseline_eval.py`](https://github.com/samer-4/priorauth-rag/blob/main/src/baseline_eval.py) (Case Workflow), [`src/stage5_generation.py`](https://github.com/samer-4/priorauth-rag/blob/main/src/stage5_generation.py) (Appeal Generation), [`src/stage1_extraction.py`](https://github.com/samer-4/priorauth-rag/blob/main/src/stage1_extraction.py) (Denial Extraction), [`src/stage2_lookup.py`](https://github.com/samer-4/priorauth-rag/blob/main/src/stage2_lookup.py) (Criteria Lookup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Case and Policy Inputs"]
  node_denial["Denial Letters"]
  node_notes["Clinical Notes"]
  node_policies["Payer Policies"]
end

subgraph group_analysis["Criteria and Evidence"]
  node_extract["Denial Extraction"]
  node_lookup["Criteria Lookup<br/>[stage2_lookup.py]"]
  node_evidence["Evidence Extraction"]
  node_sufficiency["Sufficiency Judgment"]
end

subgraph group_appeal["Appeal Workflow"]
  node_runner["Case Workflow<br/>[baseline_eval.py]"]
  node_generation["Appeal Generation"]
  node_render["Letter Rendering"]
  node_verification["Draft Verification"]
end

subgraph group_services["Model Service"]
  node_anthropic{{"Anthropic API"}}
end

node_user(("Case Submitter"))

node_user -->|"submits case"| node_runner
node_runner -->|"reads letter"| node_denial
node_runner -->|"reads notes"| node_notes
node_runner -->|"extracts details"| node_extract
node_runner -->|"reads policy"| node_policies
node_runner -->|"extracts criteria"| node_lookup
node_runner -->|"extracts evidence"| node_evidence
node_runner -->|"judges sufficiency"| node_sufficiency
node_runner -->|"generates draft"| node_generation
node_generation -->|"formats letter"| node_render
node_runner -->|"checks draft"| node_verification
node_extract -->|"requests extraction"| node_anthropic
node_lookup -->|"requests criteria"| node_anthropic
node_evidence -->|"requests evidence"| node_anthropic
node_sufficiency -->|"requests judgment"| node_anthropic
node_generation -->|"requests draft"| node_anthropic
node_verification -->|"checks claims"| node_anthropic

click node_denial "https://github.com/samer-4/priorauth-rag/tree/main/data/cases/cases_v1/denial_letters"
click node_notes "https://github.com/samer-4/priorauth-rag/tree/main/data/cases/cases_v1/notes"
click node_policies "https://github.com/samer-4/priorauth-rag/tree/main/data/policies/policies_txt"
click node_runner "https://github.com/samer-4/priorauth-rag/blob/main/src/baseline_eval.py"
click node_extract "https://github.com/samer-4/priorauth-rag/blob/main/src/stage1_extraction.py"
click node_lookup "https://github.com/samer-4/priorauth-rag/blob/main/src/stage2_lookup.py"
click node_evidence "https://github.com/samer-4/priorauth-rag/blob/main/src/stage3_evidence_extraction.py"
click node_sufficiency "https://github.com/samer-4/priorauth-rag/blob/main/src/stage4_sufficiency_judgement.py"
click node_generation "https://github.com/samer-4/priorauth-rag/blob/main/src/stage5_generation.py"
click node_render "https://github.com/samer-4/priorauth-rag/blob/main/src/stage5_generation.py"
click node_verification "https://github.com/samer-4/priorauth-rag/blob/main/src/stage6_verification.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_denial,node_notes,node_policies toneBlue
class node_extract,node_lookup,node_evidence,node_sufficiency toneAmber
class node_runner,node_generation,node_render,node_verification toneMint
class node_anthropic toneRose
class node_user toneIndigo
```

## Components

### Case and Policy Inputs

- [Denial Letters](https://github.com/samer-4/priorauth-rag/tree/main/data/cases/cases_v1/denial_letters): `data/cases/cases_v1/denial_letters`
- [Clinical Notes](https://github.com/samer-4/priorauth-rag/tree/main/data/cases/cases_v1/notes): `data/cases/cases_v1/notes`
- [Payer Policies](https://github.com/samer-4/priorauth-rag/tree/main/data/policies/policies_txt): `data/policies/policies_txt`

### Criteria and Evidence

- [Denial Extraction](https://github.com/samer-4/priorauth-rag/blob/main/src/stage1_extraction.py): `src/stage1_extraction.py`
- [Criteria Lookup](https://github.com/samer-4/priorauth-rag/blob/main/src/stage2_lookup.py): `src/stage2_lookup.py`
- [Evidence Extraction](https://github.com/samer-4/priorauth-rag/blob/main/src/stage3_evidence_extraction.py): `src/stage3_evidence_extraction.py`
- [Sufficiency Judgment](https://github.com/samer-4/priorauth-rag/blob/main/src/stage4_sufficiency_judgement.py): `src/stage4_sufficiency_judgement.py`

### Appeal Workflow

- [Case Workflow](https://github.com/samer-4/priorauth-rag/blob/main/src/baseline_eval.py): `src/baseline_eval.py`
- [Appeal Generation](https://github.com/samer-4/priorauth-rag/blob/main/src/stage5_generation.py): `src/stage5_generation.py`
- [Letter Rendering](https://github.com/samer-4/priorauth-rag/blob/main/src/stage5_generation.py): `src/stage5_generation.py`
- [Draft Verification](https://github.com/samer-4/priorauth-rag/blob/main/src/stage6_verification.py): `src/stage6_verification.py`

### Model Service

- **Anthropic API**

### Other components

- **Case Submitter**

## Connections

- Case Submitter → Case Workflow: submits case (evidence: `src/baseline_eval.py`)
- Case Workflow → Denial Letters: reads letter (evidence: `src/baseline_eval.py`)
- Case Workflow → Clinical Notes: reads notes (evidence: `src/baseline_eval.py`)
- Case Workflow → Denial Extraction: extracts details (evidence: `src/baseline_eval.py`)
- Case Workflow → Payer Policies: reads policy (evidence: `src/baseline_eval.py`)
- Case Workflow → Criteria Lookup: extracts criteria (evidence: `src/baseline_eval.py`)
- Case Workflow → Evidence Extraction: extracts evidence (evidence: `src/baseline_eval.py`)
- Case Workflow → Sufficiency Judgment: judges sufficiency (evidence: `src/baseline_eval.py`)
- Case Workflow → Appeal Generation: generates draft (evidence: `src/baseline_eval.py`)
- Appeal Generation → Letter Rendering: formats letter (evidence: `src/stage5_generation.py`)
- Case Workflow → Draft Verification: checks draft (evidence: `src/baseline_eval.py`)
- Denial Extraction → Anthropic API: requests extraction (evidence: `src/stage1_extraction.py`)
- Criteria Lookup → Anthropic API: requests criteria (evidence: `src/stage2_lookup.py`)
- Evidence Extraction → Anthropic API: requests evidence (evidence: `src/stage3_evidence_extraction.py`)
- Sufficiency Judgment → Anthropic API: requests judgment (evidence: `src/stage4_sufficiency_judgement.py`)
- Appeal Generation → Anthropic API: requests draft (evidence: `src/stage5_generation.py`)
- Draft Verification → Anthropic API: checks claims (evidence: `src/stage6_verification.py`)
