CoolFace
Apppublic

mihikajadhav/medical-coding-auditor

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

Medical Coding Auditor — OpenEnv RL Environment

Overview

An RL environment that trains AI agents to audit US medical billing claims. The agent reads freeform clinical notes and determines whether CPT procedure codes and ICD-10 diagnosis codes accurately reflect the documented services.

This environment targets the $60B/year problem of fraudulent upcoding in Medicare/Medicaid billing — a task that genuinely requires natural language understanding and cannot be solved with a rule engine.

Why This Needs RL

Clinical notes are unstructured natural language. Mapping from a freeform doctor's note to correct billing codes requires understanding medical terminology, visit complexity, and what is vs is not documented. A rule engine cannot do this — the agent must learn to reason like an experienced medical auditor across thousands of varied cases.

Task Description

The agent receives a clinical note and billing codes, then must:

  1. 1.Optionally ask clarifying questions (up to 2 per episode)
  2. 2.Submit a verdict: correctly_coded / upcoded / undercoded / fraudulent
  3. 3.Identify the specific wrong codes
  4. 4.Justify its reasoning

Action Space

FieldTypeDescription
action_typestringclarify or submit_verdict
verdictstringcorrectly_coded, upcoded, undercoded, fraudulent
flagged_codeslist[string]Codes agent believes are wrong
justificationstringPlain English reasoning
questionstringClarifying question (clarify action only)

Observation Space

FieldTypeDescription
clinical_notestringDoctor's visit note
billedcptcodeslist[string]Procedure codes billed
billedicd10codeslist[string]Diagnosis codes billed
task_difficultystringeasy / medium / hard
clarifications_usedintHow many questions asked so far
lastclarificationanswerstringAnswer to last question
feedbackstringFeedback from previous step

Reward Function

ComponentWeightGrader
Correct verdict0.40Deterministic
Correct flagged codes0.30Deterministic (Jaccard)
Justification quality0.30LLM judge with rubric
Efficiency bonus0.05Correct verdict without clarifications

Tasks

IDDifficultyDescription
easy_001EasyRoutine visit billed at complex level
easy_002EasyHypertension follow-up upcoded
medium_001MediumPhantom diagnosis added to respiratory visit
medium_002MediumComplex diabetes/CKD visit undercoded
hard_001HardSTEMI case with fraudulent pneumonia code
hard_002HardCholecystectomy with unbundled duplicate codes

Baseline Scores

Run uv run inference.py to reproduce baseline scores.

Scores below were produced with gpt-4o via the OpenAI API. The same model was used for both the auditing agent and the LLM justification judge.

DifficultyAvg ScoreNotes
Easy0.975Model solves nearly all straightforward audits
Medium0.990Model correctly handles phantom diagnoses, undercoding, and moderate upcoding
Hard0.745Model handles several complex fraud cases but still misses bundled/procedural edge cases
Overall0.903Strong baseline with remaining room on hard cases

The hard split remains the useful training signal: cases involving bundling, observation vs inpatient status, and procedure-code nuance still produce meaningful errors even when simpler documentation gaps are solved.

Setup

bash
docker build -t medical-coding-auditor .
docker run -p 8000:8000 medical-coding-auditor
cp .env.example .env   # set API_BASE_URL, MODEL_NAME, and HF_TOKEN
uv run inference.py

For OpenAI-compatible endpoints, set HF_TOKEN to the API key for that endpoint:

bash
API_BASE_URL=https://api.openai.com/v1
MODEL_NAME=gpt-4o
HF_TOKEN=your_api_key_here

For Hugging Face router models, use:

bash
API_BASE_URL=https://router.huggingface.co/v1
MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
HF_TOKEN=your_hugging_face_token_here

inference.py is in the repository root and emits only the required structured stdout lines:

text
[START] task=<task_name> env=medical-coding-auditor model=<model_name>
[STEP] step=<n> action=<json_action> reward=<0.00> done=<true|false> error=<msg|null>
[END] success=<true|false> steps=<n> score=<score> rewards=<r1,r2,...>

Deploy

bash
openenv push --repo-id your-hf-username/medical-coding-auditor --exclude .openenv-push-exclude