SpecGuard: Proving a Task Is Broken Before the Agent Cheats
cs.AI, cs.LO, cs.SE
Submitted: 2026-10-06
Updated: 2026-10-06
Comments: 29 pages. Code: https://github.com/prmbiy/specguard
Code: https://github.com/prmbiy/specguard
License: http://creativecommons.org/licenses/by/4.0/
The gist: 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.
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.
Sources
- Concrete Problems in AI Safety
- Monitoring Reasoning Models for Misbehavior and the Risks of Promoting Obfuscation
- CodeT: Code Generation with Generated Tests
- CodeSpecBench: Benchmarking LLMs for Executable Behavioral Specification Generation
- Towards Guaranteed Safe AI: A Framework for Ensuring Robust and Reliable AI Systems
- Can Large Language Models Transform Natural Language Intent into Formal Method Postconditions?
- EvilGenie: A Reward Hacking Benchmark
- MalSkillBench: A Runtime-Verified Benchmark of Malicious Agent Skills
- LiveCodeBench: Holistic and Contamination Free Evaluation of Large Language Models for Code
- SWE-bench: Can Language Models Resolve Real-World GitHub Issues?
- Intent Formalization: A Grand Challenge for Reliable Coding in the Age of AI Agents
- FormalAlign: Automated Alignment Evaluation for Autoformalization
- SWE-Proof: Can Language Models Resolve Real-World Issues with Machine-Checked Proofs?
- Natural Emergent Misalignment from Reward Hacking in Production RL
- LEVER: Learning to Verify Language-to-Code Generation with Execution
- What Can Be Enforced? A Theory of Certified Runtime Safety for Tool-Using Agents
- Clover: Closed-Loop Verifiable Code Generation
- AgentSpec: Customizable Runtime Enforcement for Safe and Reliable LLM Agents
- Semia: Auditing Agent Skills via Constraint-Guided Representation Synthesis
- Monitoring Emergent Reward Hacking During Generation via Internal Activations
Related papers
- MAVEN-T: Reinforced Heterogeneous Distillation for Real-Time Multi-Agent Trajectory Prediction
- Model Discovery Agent: LLM-assisted Bayesian experiment design for data-efficient discovery of mechanistic world models
- Agents' Last Exam
- The Clinician's Veto: Navigating Trust, Liability, and Uncertainty in Autonomous AI Prescribing
- MindHelper: Closed-Loop Embodied Mental-State Reasoning for Precision Intervention
- Incumbent Advantage: Brand Bias and Cognitive Manipulation Dynamics in LLM Recommendation Systems