Code Like Humans: A Multi-Agent Solution for Medical Coding

Andreas Geert Motzfeldt, Joakim Edin, Casper L. Christensen, Christian Hardmeier, Lars Maaløe, Anna Rogers · DOI

Abstract

Medical coding, the process of translating unstructured clinical notes into standardized ICD-10 codes, is a critical yet labor-intensive task in healthcare. Current state-of-the-art models treat this as an extreme multi-label classification problem, which often fails to scale to the full taxonomy of over 70,000 codes and struggles with rare diagnoses. This paper introduces Code Like Humans (CLH), a multi-agent framework that mimics the cognitive workflow of professional medical coders. By utilizing reasoning-enabled Large Language Models (LLMs) to navigate official indices and guidelines, CLH achieves state-of-the-art performance on rare codes and provides the first AI solution capable of supporting the entire ICD-10 code space.

Introduction

Every clinical encounter generates a narrative record that must be converted into alphanumeric codes (such as ICD-10) for billing, research, and policy-making. With over 70,000 possible codes, medical coding is a task of immense complexity. Historically, Natural Language Processing (NLP) has approached this as an "extreme multi-label classification" (XMLC) problem. Models like PLM-ICD (a BERT-based architecture) learn to map text directly to a fixed set of labels.

However, this end-to-end approach faces three fundamental hurdles:

  1. Scale: Most models are restricted to a small subset of common codes because they cannot manage the computational overhead of 70,000+ output classes.
  2. The Long Tail: Classification models rely on frequency; they excel at common diagnoses but fail on rare conditions that lack sufficient training data.
  3. Heuristic Neglect: Human coders do not memorize the entire taxonomy. Instead, they rely on an alphabetical index and a massive rulebook of guidelines—resources that standard ML models typically ignore.

The Code Like Humans (CLH) Framework

To overcome these limitations, the authors propose CLH, an agentic framework designed to follow the "Analyze-Locate-Assign-Verify" workflow used by professional organizations like the UK National Health Service. Rather than predicting codes in a single pass, CLH employs a pipeline of specialized LLM agents:

  1. Evidence Extractor: This agent identifies specific text segments within the clinical note that justify a diagnosis or procedure (e.g., "postprocedural sepsis").
  2. Index Navigator: Using the extracted evidence, this agent queries the official ICD alphabetical index to retrieve a list of candidate codes, effectively turning a classification problem into a retrieval problem.
  3. Tabular Validator: This agent retrieves specific chapter guidelines for the candidate codes. It applies these rules to resolve ambiguities and ensure the clinical context matches the code requirements.
  4. Code Reconciler: The final agent reviews instructional notes regarding mutually exclusive codes and sequencing rules to produce a final, ordered list of ICD-10 codes.

CLH is powered by reasoning-enabled LLMs (such as DeepSeek-R1 and OpenAI’s o-series), which utilize a "thinking" phase to process complex instructions before generating an output.

Experimental Methodology

The framework was evaluated using two primary datasets:

  • MIMIC-III: The industry-standard database for medical coding research.
  • MDACE: A high-quality dataset featuring 4,000 human-verified annotations that link ICD codes directly to evidence spans within MIMIC-III notes. This dataset is particularly useful for evaluating the granular accuracy of an agentic pipeline.

Key Insights

Retrieval vs. Memorization

CLH’s primary advantage lies in its ability to handle the "long tail" of rare codes. Because it retrieves codes dynamically from the index rather than relying on learned weights from training data, it is not biased toward frequent codes. In evaluations on the MDACE dataset, CLH achieved a Macro F1 score of 0.28, outperforming the PLM-ICD baseline (0.25). Since Macro F1 weights all classes equally, this result confirms CLH’s superior performance on rare diagnoses.

The Importance of Reasoning Tokens

The study found that the "thinking" phase of reasoning LLMs is essential. Allowing the model to generate an internal chain-of-thought significantly outperformed models forced to use structured decoding. This reasoning allows the agents to effectively apply the 115-page ICD-10 guideline rulebook in-context.

Architectural Limitations of Standard LLMs

In an ablation study, the authors found that standard autoregressive LLMs (like Llama-3.2) perform poorly on medical coding compared to BERT-based models. The reason is architectural: BERT-based models use "label-wise attention," which allows the model to focus on specific parts of the text for every possible code. When the authors added label-wise attention to the Llama model, its performance improved drastically, suggesting that standard causal language modeling heads are inherently disadvantaged for XMLC tasks.

Conclusion and Future Work

CLH represents a paradigm shift in medical coding, moving from black-box classification to a transparent, human-like reasoning process. It is the first system to support the full 70,000+ ICD-10 taxonomy at inference time.

Despite its success, the system faces challenges with "cascading errors"—if the Evidence Extractor misses a detail, the entire pipeline fails. It also struggles with nuances like medical abbreviations and social qualifiers. Future work will focus on implementing self-refinement loops and fine-tuning individual agents for their specific sub-tasks. Ultimately, CLH is envisioned as an assistive tool to reduce the cognitive burden on human coders rather than a full replacement.

Summary updated

BibTeX
@misc{motzfeldt2025code,
  author = {Andreas Geert Motzfeldt and Joakim Edin and Casper L. Christensen and Christian Hardmeier and Lars Maaløe and Anna Rogers},
  title = {{Code Like Humans: A Multi-Agent Solution for Medical Coding}},
  year = {2025},
  eprint = {2509.05378},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.05378},
}
Figure