arXiv:2609.01095cs.SESep 2026

Manuscript Offprint

arXiv:2609.01095

Reliable LLM-Generated Programs for High-Energy Physics Experiments through Graph-Grounded Software Knowledge

Yue Sun, Tong Liu, Yipu Liao, Jingde Chen, Ke Li

Yue Sun, Tong Liu, Yipu Liao, Jingde Chen, and Ke Li*

Institute of High Energy Physics, Chinese Academy of Sciences, Beijing 100049, China and University of Chinese Academy of Sciences, Beijing 100049, China

Extracting physics information from modern particle-physics experiments requires multistage analyses implemented on top of large and highly interconnected software ecosystems. General-purpose large language models (LLMs) often produce unreliable programs for such tasks because a user request alone rarely specifies the required APIs, dependencies, and usage conventions. We organize these software relations before generation and retrieve task-relevant knowledge at inference time. Using the open-source ROOT framework as a representative and reproducible testbed, we evaluate a complete grounding system that combines hybrid retrieval over a heterogeneous software knowledge graph, skill-selected workflow examples, and execution-guided repair. On a benchmark of 275 ROOT tasks, grounding improves first-attempt execution from 58.5% to 76.0% under Claude Code orchestration and from 51.3% to 64.0% under standalone orchestration. Final success increases from 90.5% to 96.0% and from 78.9% to 90.9%, respectively, while the average generation cost per successful task increases by only 1.3% and 3.2%. The gains persist under a strong coding agent, indicating that explicit software knowledge remains valuable even when agentic scaffolding is already in place. Because the method captures software relations common to large codebases rather than facts specific to ROOT or a particular model, it should transfer to other experiment frameworks and proprietary software, especially where documentation is sparse or internal dependencies are complex.

I. INTRODUCTION

Modern high-energy physics experiments are complex at every level. Detectors contain many interacting subsystems, data pass through multistage reconstruction and calibration chains, and physical results emerge only after simulation, statistical inference, analysis, and visualization. Translating detector observations into physics knowledge therefore requires increasingly sophisticated programs. These programs, in turn, depend on extensive scientific software stacks whose packages, interfaces, and version-specific relations must be combined correctly. Reliable physics results depend on more than the data and physical model. The analysis program must also use the surrounding software correctly.

Large language models (LLMs) have evolved from local completion tools into coding agents capable of inspecting repositories, executing pr ograms, and revising their outputs [1, 2]. Such agents could reduce the implementation effort required to translate high-level physics requirements into executable analysis programs. General programming ability alone, however, does not ensure a reliable scientific program. A generated script may appear syntactically convincing while calling a nonexistent method, selecting an obsolete overload, omitting a required dependency, or combining valid APIs into a workflow that fails at runtime.

Recent HEP domain-agent systems make the connection between scientific autonomy and executable software explicit. JFC uses a coding-agent runtime, literature retrieval, and multi-agent review to plan and execute

experimental analyses on ALEPH, DELPHI, and CMS open data, covering event selection, background estimation, systematic uncertainties, statistical inference, and documentation [3]. SciFi provides an isolated, iterative execution environment and demonstrates autonomous data processing, ROOT fitting and visualization, reproduction of a published calorimeter-simulation pipeline, and HEP data-acquisition firmware debugging and implementation [4]. ColliderAgent couples specialized subagents to a unified backend that orchestrates FeynRules, MadGraph, Pythia, Delphes, and MadAnalysis for workflows from theoretical Lagrangians to detector-level studies and exclusion limits [5], whereas PhysMaster combines literature-grounded planning, executable numerical calculation, and fitting to automate renormalization, extrapolation, and Collins-Soper-kernel extraction from lattice-QCD inputs [6]. Across these otherwise distinct domains, scientific results are reached by generating, configuring, executing, debugging, or validating code and software workflows. HEP agents ultimately depend on code to carry out their analyses. Making that code more reliable should make the agents themselves more useful in practice.

The required dependencies are not arbitrary: they are encoded in the organization of the software and can be extracted before a user submits a request. Files contain classes, headers declare interfaces, include statements record dependencies, and inheritance links expose reusable behavior. We organize these relations as structural grounding in a software graph and retrieve the relevant neighborhood at inference time [7–14]. Official examples add procedural grounding by showing how multiple APIs form complete workflows. Program execution then provides diagnostic grounding: failures are converted into targeted repair context instead of being appended as unstructured logs [15–18]. These three sources of evidence serve differ-

ent purposes. They identify valid software components, show how those components fit together, and help correct the program after a failed run.

We test this strategy with ROOT, the open-source C++ framework widely used for particle-physics data analysis, statistics, fitting, and visualization [19]. ROOT is a useful test case for two practical reasons. It is widely used in experiments, and its open repository makes the dependency graph reproducible and easy to inspect. Recent studies have explored LLM support for research software and high-energy-physics workflows [20–24]. The grounding workflow is also used in Dr.Sai, where it supports ROOT program generation within a broader multi-agent pipeline for BESIII physics analysis [25]. Here, we evaluate the structural, procedural, and diagnostic grounding components as one executable ROOT workflow. The system retrieves graph and example evidence before initial generation and uses execution evidence to guide bounded repair. We compare the grounded workflow with direct generation in two orchestration implementations that use the same generation model.

The evaluation is organized around three research questions:

RQ1 Effectiveness: How do executable success and final-program quality compare between the complete grounding system and direct generation?

RQ2 Repair: How does grounding change repair burden and failure recovery, and does Error-RAG improve repair relative to direct error feedback?

RQ3 Efficiency and robustness: What resource trade-offs accompany grounding, and are the observed trends consistent across orchestration settings?

To our knowledge, this is the first systematic study in experimental particle physics to ground LLM-generated analysis programs and their repair in a preconstructed graph of framework dependencies. This work has three main contributions. First, we formulate and implement a ROOT program-generation workflow that combines repository structure, skill-selected workflow examples, and execution feedback as structural, procedural, and diagnostic grounding. Second, we evaluate the grounded system against direct generation in two orchestration implementations on a 275-task benchmark. Third, we characterize executable success, final-program quality, repair dynamics, resource overhead, and failure modes, and add a repair-stage ablation of Error-RAG against direct error feedback. The same dependency relations and retrieval procedure could be used with detector simulation, experiment-specific software, large scientific libraries, and proprietary systems, provided that source repositories or interface metadata are available. For high-energy-physics applications, the method may reduce time spent resolving software dependencies and support more reproducible analysis workflows.