Abstract
Changes to application programming interfaces (APIs) can stop quantum programs from running, while incorrect gates or qubit ordering can produce wrong results without raising errors. We study how grounding large language models (LLMs) affects the detection and repair of such defects. Our system, LintRepair-RAG-Q , combines static analysis, a retrieval-supported LLM detector, and a repair loop that receives analyser findings and retrieved defect-knowledge entries and checks each patch by executing it. We evaluate it on Q-Defects40 , 40 Qiskit programs across eight defect families, using eighteen models, including open-weight models with 3 to 72 billion parameters. Combining the static and LLM detectors raises recall from 0.72 to 0.81 with no false positives on 40 negative examples. The grounded repair system improves pooled accuracy by 16 percentage points (p < 0.001), with an effect that varies by defect type: a 50-point gain on API-migration defects, no net change on structural ones, and a 9-point decline on semantic defects that run but return incorrect output. Within the migration-free semantic group, models with higher baseline executability — the fraction of unguided patches that execute — show larger losses after adjusting for baseline accuracy (partial correlation −0.57, 95% interval [−0.85, −0.17]). We release the benchmark, system, and scripts. Keywords: Quantum software engineering, Program repair, Static analysis, Large language models, Retrieval-augmented generation, Competence-dependent evaluation