SpecGuard: Proving a Task Is Broken Before the Agent Cheats
Abstract
As autonomous coding agents get increasingly deployed, the risk that accidental or adversarially injected misspecifications in tasks lead to dangerous agent behavior is critical to address. Prior work has shown that agents given such tasks rarely flag the conflict and instead cheat, editing tests or hard-coding expected outputs, and the actions taken to cheat can cause real damage, such as deleting a security defense to make a corrupted test pass. It remains unclear whether such conflicts can be established with independently verifiable evidence before the agent acts. We present SpecGuard, which detects and formally certifies these conflicts between task intent and tests. Given only the task description and codebase, SpecGuard autoformalizes the intended behaviour into a Lean 4 specification. The tests are formalized independently, and the Lean kernel checks whether any implementation could satisfy both formalizations, producing a machine-checked certificate when none can. On conflicted SWE-bench tasks, SpecGuard detects up to 72.8% of conflicts and formally certifies up to 51.1%, with a nearly five-fold lower conflict miss rate than model-based judgment. SpecGuard provides a pre-execution safety check that identifies reward-hacking opportunities through formal certification of task-level conflicts, before any agent behavior is observed. Our code is available at https://github.com/prmbiy/specguard.
Create a lesson
Metadata
- Categories
- cs.AI, cs.LO, cs.SE
- Comments
- 29 pages. Code: https://github.com/prmbiy/specguard
Related papers
Learning What vs. Learning How: Decomposing Task and Interface Competence in Agentic Training
Shared title terminologycs.AIChaeeun Lee, Hossein A. Rahmani, Aryo Pradipta Gema et al.
MMMem: Self-Improving Agents with Task-Aware Multimodal Experience Consolidation
Shared title terminologycs.AIYuxuan Chen, Changwei Lv, Yunfei Li et al.
AgentHorizon: Evaluating Agentic Judges for Long-Horizon Computer-Use Tasks
Shared title terminologycs.AIXing Han Lù, Dheeraj Vattikonda, Sina Hajimiri et al.
Cost-Efficient Theorem Proving via Agent Orchestration in Program Verification
Shared title terminologycs.AIShuangjie Yao, Nikolaus Holzer, Mark Paul Santolucito et al.
GeoNatureAgent (GNA): A Framework and Benchmark for Pre-Production Evaluation of Tool-Using Agents on Geospatial and Environmental Tasks
Shared title terminologycs.AIGabriel Diaz-Ireland, Diego Prieto-Herráez, Mario García Peces et al.
Learning to Report Unsafe Tasks in a Multi-Agent Game
Shared title terminologycs.AIAvyay M. Casheekar, Hariganesh Tangirala