Splitting it into layers (and specialized agents)
Payer normalization, pattern recognition, X12 mapping and rule generation as separate problems.
First published on LinkedIn.
Last week I shared my initial test extracting UHC's smart edits into structured JSON. The extraction worked—but it quickly became clear that one monolithic LLM call couldn't handle the full complexity at scale.
I soon realized this isn't a single problem. It's multiple distinct problems that need to work in sequence:
Layer 1: Payer Normalization — Each payer formats their edits differently. UHC uses Smart Edit IDs with table layouts. Anthem uses different patterns. A specialized ingestion agent per payer normalizes everything into a canonical format before any X12 mapping happens.
Layer 2: Pattern Recognition — Identify what type of validation this is:
FOREACH: "For each service line, validate X"
AGGREGATE: "Sum all line amounts must equal claim total"
WHEN: "If claim type = Y, then require Z"
Layer 3: X12 Mapping — Map natural language to actual X12 segments and elements. "CLIA number" → REF segment with qualifier X4. "Procedure code" → SV101-2 (professional) or SV202-2 (institutional).
Layer 4: DSL Generation — Convert everything into executable validation rules:
FOREACH LOOP('2400') AS service
ASSIGN procedureCode = SV1*01-2
ASSIGN modifiers = SV1*01-3
REQUIRE NOT IS_SINGLE_DOSE_DRUG(procedureCode)
OR (modifiers CONTAINS 'JW' OR modifiers CONTAINS 'JZ')
MESSAGE "Procedure {{procedureCode}} requires JW or JZ modifier"
The DSL (domain specific language) handles loop iteration, external lookups, and variable interpolation for rejection messages. I'll show how I envision the DSL being used and validated against X12, and not just healthcare, in a future post. But for now, we'll focus on how to build 837 claim validation rules from the periodic edits released by payers.
Layer 3 (X12 mapping) is still monolithic. Lab services, surgical procedures, DME, and pharmacy claims all have different X12 patterns and domain requirements. Next up, I'm experimenting with LangGraph to break this into specialized medical domain agents — each understanding the nuances of their specific claim type.
Still a long way from done, but the failures are getting more interesting.