SHERLOC: Structured Diagnostic Localization for Code Repair Agents

Hovhannes Tamoyan, Sean Narenthiran, Erik Arakelyan, Mira Mezini, Boris GinsburgarXiv 2026

TL;DR

LLM agents designed for repository-level code repair waste nearly half of their token and interaction budgets just trying to find where a bug is located. This paper introduces SHERLOC, a training-free framework that pairs a single reasoning LLM with a compact suite of tools to not only locate bugs with state-of-the-art accuracy but also provide rich, structured diagnostic context. By telling downstream repair agents why a file is broken and how to fix it, SHERLOC boosts patch success rates by an average of 5.95 percentage points while slashing total token costs by over 23%.

What Problem Does This Paper Address?

When an AI agent is tasked with fixing a bug in a massive software repository (a task popularized by benchmarks like SWE-Bench), it must complete two distinct phases: localization (finding the faulty code) and repair (writing and verifying the patch).

The authors reveal a massive bottleneck: agents spend an average of 18.5 turns—accounting for 48% of their entire interaction loop and over 320k tokens—just trying to locate the fault before making their first edit.

Worse yet, existing standalone localization tools treat this purely as an information retrieval problem, returning a file path or function name without any context. A file path tells an agent where to look, but not why the code is broken or how it should be fixed. Without a root-cause hypothesis, downstream repair agents are left guessing, which leads to failed patches and wasted compute.

Methods

SHERLOC (Structured Hypothesis-driven Exploration and Reasoning for Localization) is a training-free, single-agent framework that turns localization into an active, diagnostic reasoning process.

Overview of the SHERLOC framework, combining a reasoning LLM with compact repository tools and a self-recovery layer.

The architecture consists of three core pillars:

  1. LLM-Friendly Tools: Instead of giving the agent raw shell access (which frequently derails trajectories due to syntax errors), SHERLOC provides a deterministic executor with four highly structured tools: View File (with fuzzy path matching), Codebase Search (literal string matching), Repository Tree (filtered directory structure), and Connected Tree (navigating import/dependency graphs).
  2. Lightweight Self-Recovery: To prevent the agent from getting stuck in extended multi-turn loops, SHERLOC implements automated safeguards. These include loop detection (warning the agent if it repeats commands), context management (truncating older observations), and implicit tool-call recovery (parsing malformed requests).
  3. Structured Diagnostic Findings: When SHERLOC finishes its search, it doesn't just output line numbers. It generates a structured finding containing five fields: location explanation, root cause, solution idea, dependencies, and testing impact.

The authors also introduce a new structure-agnostic chunk-level metric that evaluates localization based on exact line-number spans rather than arbitrary syntactic units like functions or classes.

Datasets

The framework was evaluated on two standard repository-level code repair benchmarks derived from real-world GitHub issues:

  • SWE-Bench Lite: A subset of 300 instances used to benchmark baseline localization accuracy.
  • SWE-Bench Verified: A human-vetted subset of 500 instances used to test both localization and downstream transfer to code-repair frameworks.
  • SWE-Gym: A development set utilized for component ablations.

Key Insights and Ideas

  • Diagnostic Context is the Operative Unit: Simply finding the right file isn't enough. If an agent receives a correct file path but a misleading diagnosis, it will write a bad patch. Conversely, providing a clear "solution idea" acts as a powerful anchor that guides the repair agent directly to a successful fix.
  • The "Thinking Mode" Imperative: The authors compared a reasoning model (Qwen3-Thinking) against its standard instruction-tuned counterpart (Qwen3-Instruct). The instruct model suffered a near-total collapse, failing to produce valid outputs 87% of the time. Extended chain-of-thought reasoning is absolutely critical for sustaining complex, multi-turn exploration protocols.
  • Parametric Familiarity vs. Active Exploration: Because SWE-Bench repositories are public, LLMs inherently remember some bug locations from pretraining. By masking file paths in the issue descriptions, the authors isolated this "implicit knowledge" confound. They found that while implicit memory helps on popular repos, SHERLOC’s active tool use provides a massive ~22 percentage point boost over relying on memory alone.

Key Results

SHERLOC achieves state-of-the-art localization performance across model scales without any task-specific fine-tuning or reinforcement learning.

Localization performance of SHERLOC compared to prior systems on SWE-Bench Lite and Verified.
  • Localization Accuracy: Powered by Qwen3-235B, SHERLOC achieved 84.33% accuracy@1 on SWE-Bench Lite and 81.27% recall@1 on SWE-Bench Verified, outperforming heavily optimized and fine-tuned baselines.
  • Downstream Repair Boost: When SHERLOC's diagnostic findings were injected into existing repair frameworks (SWE-Agent and OpenHands) across 5 different model backbones, it yielded an average +5.95 percentage point gain in issue resolution rate.
  • Compute Efficiency: By providing a targeted starting point, SHERLOC cut localization token costs by 36.7% and total full-run token costs by 23.1% on average. For massive models like Qwen3-Coder-480B, injecting SHERLOC findings cut localization tokens by a staggering 66%.

Limitations and Future Work

  • The Pretraining Confound: Despite rigorous masking controls, the framework is still evaluated on open-source repositories that the underlying LLMs may have seen during pretraining. Evaluating SHERLOC on strictly private or newly minted codebases remains an open challenge.
  • Language Scope: While the core framework is language-agnostic, the Connected Tree tool relies on a thin, Python-specific import parser. Expanding to languages like JavaScript, Java, or C++ will require adapting this parser.
  • Prompt Sensitivity: The framework shows sensitivity to how different model families handle system prompts (e.g., DeepSeek-R1 occasionally bypassed tool use entirely). Future work will need to focus on model-specific prompt adaptation for commercial APIs.

Summary updated

BibTeX
@misc{tamoyan2026sherloc,
  author = {Hovhannes Tamoyan and Sean Narenthiran and Erik Arakelyan and Mira Mezini and Boris Ginsburg},
  title = {{SHERLOC: Structured Diagnostic Localization for Code Repair Agents}},
  year = {2026},
  eprint = {2606.24820},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2606.24820},
}
Figure