The Last Mile of Coding Agents for Long-Document Tasks: An Empirical Study on Clinical Trial Protocol Digitization

Jiacheng Lin, Geoffrey Low, Nishit Agarwal, Rahul Jain, Afrah Shafquat, Mandis Beigi, Jimeng SunarXiv 2026

TL;DR

This paper investigates the "last mile" problem of coding agents—autonomous LLMs equipped with tools—when tasked with digitizing complex, 100+ page clinical trial protocols. The authors introduce TRIALPD-BENCH, a new expert-annotated benchmark, and demonstrate that while agents are excellent at finding relevant information, they frequently stumble when transcribing and structuring it. To bridge this gap, they developed TRIALSCRIBE, a domain-specific harness that enables local open-weight models to match or even outperform proprietary giants like GPT-5.6-Sol.

What Problem Does This Paper Address?

Clinical trial protocols are the "source of truth" for medical studies, yet they are almost exclusively trapped in unstructured, lengthy PDF documents (often exceeding 100 pages). Manually digitizing these into machine-readable formats is slow, expensive, and prone to errors that can compromise trial safety or regulatory compliance.

While modern coding agents (like Claude Code or OpenAI’s Codex) have shown promise in software engineering, their reliability in high-stakes "long-document" tasks remains unproven. These tasks require more than just text retrieval; they demand the ability to navigate complex layouts, resolve merged table cells, and link information scattered across dozens of pages. The authors identify a critical bottleneck: agents often locate the correct evidence but fail in the "last mile" of faithful transcription and relational structuring.

Overview of the study: (a-c) challenges in protocol digitization, (d) cost vs. performance, and (e) the impact of TrialScribe.

Methods

The researchers evaluated nine different models (both proprietary and open-weight) using five different agent harnesses. To improve performance, they introduced TRIALSCRIBE, a specialized harness designed to support agents in two ways:

  1. Task Skills: A set of domain-specific guidelines (provided as a SKILL.md file) that teaches the agent how protocols are typically organized, which conventions to follow (like USDM v4.0 standards), and how to handle common PDF pitfalls.
  2. Verification Loop: After an agent generates a draft, a separate "auditor" agent session reviews the output against the source document. It identifies errors, cites specific page numbers, and suggests corrections. The original agent then applies these fixes in a multi-turn refinement process.

This approach was compared against standard RAG (Retrieval-Augmented Generation) pipelines and specialist OCR/document-understanding models.

Datasets

The authors introduced TRIALPD-BENCH, a benchmark consisting of 150 unique clinical trial protocols (median length: 122 pages). The benchmark covers four key task categories:

  • Disease Indication: Identifying the specific condition under study.
  • Eligibility Criteria: Extracting inclusion and exclusion rules.
  • Objectives & Endpoints: Linking study goals to their measurable outcomes.
  • Schedule of Activities (SoA): Reconstructing complex visit-by-activity tables.

Unlike previous datasets that often use simplified registry text, TRIALPD-BENCH uses full, messy, real-world PDFs, including those with garbled text layers that require visual recovery (OCR).

Key Insights and Ideas

  • The "Last Mile" Failure: The most striking finding is that agents usually find the right pages (high evidence recall) but fail to transcribe the data accurately. For example, an agent might correctly locate the eligibility section but change a "≥" to a ">", a small character shift with massive clinical implications.
  • Relational Complexity is the Killer: Agents perform well on contiguous text (Indication F1 ~85%) but struggle significantly with relational tasks like linking endpoints to objectives or building structured timelines.
  • Coding Agents > RAG: Coding agents significantly outperform traditional RAG pipelines. The flexibility of an agent to adjust its document-processing strategy on the fly is far more effective than a fixed retrieval-and-generation pipeline.
  • Cost is Not a Proxy for Quality: The study found that some frontier agents are several times more expensive than others while providing similar accuracy. Furthermore, with the right harness (TRIALSCRIBE), a much cheaper, locally-served model can outperform expensive proprietary ones.
Failure analysis showing that while agents often find the right pages, they fail at transcription and relational reconstruction.

Key Results

  • TrialScribe Boost: TRIALSCRIBE improved the performance of the open-weight Qwen3.8-27B model by 6.2 to 59.4 points across various metrics.
  • Matching the Giants: With the TRIALSCRIBE harness, the local Qwen model matched or surpassed GPT-5.6-Sol on endpoint extraction and timeline activity recall.
  • OCR Superiority: General-purpose coding agents were found to be more accurate at transcribing complex Schedule of Activities (SoA) tables than specialist document-understanding models like Mistral OCR or PaddleOCR.
  • Task Difficulty: The "Schedule of Activities" task proved the most difficult, with even the best agents reaching only ~86% F1, highlighting that fully autonomous protocol digitization is not yet a solved problem.

Limitations and Future Work

The authors acknowledge several limitations:

  • Small Timeline Sample: The structured timeline extraction task was evaluated on only three protocols due to the extreme complexity of the reference annotations.
  • Task Scope: The study focused on four specific digitization tasks; protocols contain many other table types (e.g., dosing, safety assessments) that were not covered.
  • Relational Gaps: Despite improvements, a significant gap remains in reconstructing complex relational structures, suggesting that future work should focus on better reasoning over document-wide relationships rather than just better retrieval.

The researchers suggest that extending TRIALPD-BENCH to more table types and further refining the verification loops are the most promising paths forward for reaching full automation in clinical trial digitization.

Summary updated

Abstract

Clinical trial protocols serve as the source of truth for study design, but are mostly written and used as unstructured PDF documents. Digitizing protocols turns static content into structured, machine-readable data that clinical software can analyze, validate, and execute. Coding agents, which select tools, execute code, and revise their approach as they work, are increasingly applied to such long-document tasks, yet it remains unclear how reliably they turn complete documents into accurate structured outputs. We study this question using protocol digitization as a testbed. We introduce TrialPD-Bench, an expert-annotated benchmark of 150 publicly available protocol PDFs spanning four task categories. Beyond final-answer performance, our evaluation measures evidence recall from agent traces, agent behavior, and cost. Across nine proprietary and open-weight models in five coding-agent harnesses, even the strongest agents do not fully solve protocol digitization. Our analysis further shows that agents usually locate the required evidence but fail in the last mile of transcribing and structuring it. We further develop TrialScribe, a domain-specific harness that equips coding agents with task skills and a verification loop. TrialScribe improves a locally served open-weight model by 6.2-59.4 points across eight metrics, enabling it to match or surpass proprietary models such as GPT-5.6-Sol.
BibTeX
@misc{lin2026last,
  author = {Jiacheng Lin and Geoffrey Low and Nishit Agarwal and Rahul Jain and Afrah Shafquat and Mandis Beigi and Jimeng Sun},
  title = {{The Last Mile of Coding Agents for Long-Document Tasks: An Empirical Study on Clinical Trial Protocol Digitization}},
  year = {2026},
  eprint = {2610.18507},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2610.18507},
}
Figure