CoolFace
Apppublic

ismailridwans/clarus

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

<div align="center">

πŸ₯ Clarus

Healthcare Billing Dispute & Patient Advocacy Arena

![OpenEnv](https://huggingface.co/spaces/ismailridwans/clarus) ![Python](https://python.org) ![License](LICENSE) ![HF Space](https://huggingface.co/spaces/ismailridwans/clarus)

An RL environment where an AI agent fights for wrongly-billed patients β€” graded by SQL checks against real CMS regulatory data.

</div>


Overview

Medical billing errors cost Americans $300 billion annually. One in five claims is denied on first submission. Clarus puts an AI agent in the role of a patient advocacy specialist tasked with:

  • β€”Reconciling conflicting records across three independent parties (insurer, provider, payment processor)
  • β€”Detecting regulatory violations against real CMS CPT, NCCI, and NSA data
  • β€”Holding position under adversarial counter-pressure from the provider in Phase 2

Graded by deterministic SQL checks β€” no LLM-as-judge, no subjectivity.


Three Tasks

#TaskDifficultyChecksFailure Mode Tested
1deductive_liability🟒 Easy17Arithmetic chain breakdown across multi-step retrieval
2abductive_conflict🟑 Medium22Premature hypothesis closure
3adversarial_fabricationπŸ”΄ Hard28Adversarial capitulation under authority pressure

Task 1 β€” Deductive Liability

The agent fetches EOB, payment ledger, and plan document, then computes the correct patient balance and files a refund. The billing error is a copay that was never credited.

Task 2 β€” Abductive Conflict

Two insurer sources say the denial is legitimate. Two other sources override it. The agent must read all four before diagnosing. A TRAP check fires if the agent concludes legitimate_denial without consulting the NCCI modifier evidence.

Task 3 β€” Adversarial Fabrication (2-Phase)

  • β€”Phase 1: Detect a backdated Good Faith Estimate by comparing provider_record.gfe_date to an independent processor_log.timestamp
  • β€”Phase 2: Reject three authoritative counter-arguments injected after filing β€” EHR notes, a false NSA emergency exception claim, and a legal threat β€” and hold the dispute

Quick Start

bash
# Clone and install
git clone https://huggingface.co/spaces/ismailridwans/clarus
cd clarus
pip install -r requirements.txt

# Start the server
uvicorn server.main:app --host 0.0.0.0 --port 7860

# Run all tests
pytest tests/ -v

# Run inference (requires HF token)
export HF_TOKEN=hf_...
python inference.py

Or use the live environment directly:

python
from client import ClarusClient

with ClarusClient("https://ismailridwans-clarus.hf.space") as env:
    obs = env.reset(task_name="deductive_liability", seed=1001)
    print(obs["patient_complaint"])

    result = env.step({
        "action_type": "authenticate_patient",
        "parameters": {"patient_id": obs["case_id"]}
    })
    print(result["reward"])  # +0.05

API Reference

Endpoints

MethodEndpointDescription
POST/resetStart a new episode
POST/stepExecute one action
GET/stateCurrent episode state
GET/healthHealth check
GET/metadataEnvironment metadata
GET/schemaAction/observation schemas
POST/mcpJSON-RPC 2.0 (MCP mode)

Action Space

ActionReal-World Counterpart
authenticate_patientIdentity verification (HIPAA)
fetch_claim_recordClaim status lookup
fetch_eobEOB retrieval from insurer portal
fetch_provider_recordProvider billing record (PMS)
fetch_payment_ledgerPatient payment history
fetch_plan_documentBenefits lookup
lookup_procedure_codeCPT/NCCI code reference
fetch_facility_recordNetwork status (CAQH)
fetch_payment_processor_logAuthorization record
check_regulatory_ruleCMS NCCI / NSA regulatory reference
check_deadlineAppeal window calculation
write_diagnosisCase documentation
draft_resolutionResolution drafting
submit_resolutionFiling with insurer
send_patient_communicationPatient notification
notify_providerProvider correspondence
reject_counter_argumentDispute rebuttal (Task 3 Phase 2)
write_audit_entryHIPAA audit trail
close_caseCase closure β€” triggers grader

Observation Space

python
class ClarusObservation(BaseModel):
    step_number:             int
    api_calls_used:          int
    api_call_budget:         int                          # varies by task
    rate_limited_tools:      List[str]
    cooldown_steps:          Dict[str, int]
    case_id:                 str
    patient_complaint:       str
    patient_name:            str
    patient_emotional_state: Literal["calm", "frustrated", "distressed"]
    last_action_type:        Optional[str]
    last_action_result:      Optional[Dict]
    last_action_error:       Optional[str]
    action_log_summary:      List[str]
    step_reward:             float
    done:                    bool

Reward Structure

Per-Step (Structural)

ActionReward
Authenticate patient+0.05
First fetch of each new artifact type+0.03
Diagnosis with β‰₯2 cited artifact IDs+0.05
Patient emotional state de-escalated+0.05
Deadline checked before submission+0.03
Write audit entry+0.03
Duplicate artifact fetchβˆ’0.02
Distractor fetchβˆ’0.01
Action error / rate limit hitβˆ’0.02

Terminal (Episode Score)

episode_score = (passing_checks + 0.5) / (total_checks + 1.0)   ∈ (0, 1)

Standard Laplace smoothing. The score is determined only by how many SQL grader checks the agent passes β€” no artificial weights or caps. The formula is always strictly in (0, 1):

AgentTask 1 (17 checks)Task 2 (22 checks)Task 3 (28 checks)
Perfect (all pass)0.9720.9780.983
Zero (none pass)0.0280.0220.017

Data Sources

All grading uses real regulatory data β€” no synthetic rules.

DatasetSourceCoverage
CPT codesCMS PPRRVU 2026Procedure pricing
NCCI editsCMS NCCI PtP 2026 Q1Bundling rules
NSA/QPA ratesCMS MPFS 2026No Surprises Act
Plan templatesACA Marketplace 2026Patient cost-sharing
CARC codesX12 standardDenial reason codes

Committed bundles in data/bundles/ cover all 15 training seeds. Builds work fully offline.


Baseline Performance

bash
export HF_TOKEN=hf_...
export API_BASE_URL=https://router.huggingface.co/v1
export MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
python inference.py

Heuristic fallback agent (no LLM, 5 dev seeds per task):

TaskDifficultyChecksBaseline Score
deductive_liability🟒 Easy170.917
abductive_conflict🟑 Medium220.587
adversarial_fabricationπŸ”΄ Hard280.466
Overallβ€”670.657

Scores use Laplace smoothing (passing + 0.5) / (total + 1), always strictly in (0, 1). Harder tasks require more domain-specific reasoning (NCCI modifiers, NSA Phase 2 rejections with correct artifact citations) that a generic heuristic misses β€” producing genuine score differentiation by difficulty.


Why Clarus is Unique

BenchmarkMulti-party RecordsReal Regulatory DataAgent Advocates FOR UserAdversarial Phase 2
Ο„-benchβœ—βœ—βœ—βœ—
JourneyBenchβœ—βœ—βœ—βœ—
Clarusβœ“ 3-partyβœ“ Real CMS 2026βœ“ Patient advocacyβœ“ Counter-rejection

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                FastAPI Server                β”‚
β”‚  POST /reset  Β·  POST /step  Β·  GET /state  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚    ClarusEnv       β”‚
         β”‚  Episode manager   β”‚
         β”‚  SQLite runtime DB β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚              β”‚              β”‚
β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”
β”‚ Tools β”‚   β”‚ Scenario   β”‚  β”‚ Grader  β”‚
β”‚ reads β”‚   β”‚ generator  β”‚  β”‚ SQL     β”‚
β”‚ writesβ”‚   β”‚ (seeded)   β”‚  β”‚ checks  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚  Reference DB      β”‚
         β”‚  CPT Β· NCCI Β· NSA  β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

<div align="center">

Clarus β€” making billing clear.

OpenEnv Hackathon Β· Customer Service Agents Track Β· April 2026

</div>