AgentGuard improves AI coding agent reliability by learning from failures

AgentGuard: Learning Execution Guardrails from Anomalous Coding-Agent Trajectories

Software Engineering

Summary

AI coding helpers sometimes make mistakes like changing wrong files or ignoring errors. The authors created AgentGuard, a tool that learns from past AI mistakes to set smart rules that prevent such errors during code writing. Instead of using fixed safety rules, AgentGuard adjusts its checks based on what problems usually happen. Tests showed that AI coding helpers using AgentGuard made fewer mistakes and completed tasks more often. This approach helps make AI coding assistants safer and more reliable.

What this means in practice

  • For software development teams: Improve the reliability of AI coding assistants in complex projects by reducing execution errors through learned behavioral constraints.
  • For automated devops engineers: Use execution guardrails learned from prior failures to prevent unsafe commands and unintended code changes in automated deployment pipelines.

Authors

Wuyang Dai, Song Wang

Abstract

AI coding agents increasingly rely on execution harnesses to interact with repositories and external tools. However, task success does not guarantee reliable execution. Agents may still modify unrelated files, rewrite tests, issue unsafe commands, or ignore failed validations, motivating behavioral guardrails for reliable execution. We present AgentGuard, an instruction-level guardrail framework that learns conditional execution constraints from anomalous trajectories of coding agents. Rather than relying on manually specified safety rules, AgentGuard automatically extracts recurring execution failure patterns, generalizes them into instruction-level behavioral constraints, and organizes them as a lightweight guardrail skill that dynamically activates only the rules relevant to the current instruction. This design enables behavioral guidance while minimizing unnecessary restrictions on normal execution. We evaluate AgentGuard using 642 documented failure traces collected from real coding-agent executions across 382 repository tasks. Guardrails are learned from 461 traces covering 282 tasks and evaluated on a disjoint set of 100 tasks. Using Claude Code with Claude Haiku 4.5 as the underlying coding agent, we compare the baseline agent with the same agent augmented by AgentGuard. Experimental results show that AgentGuard reduces the Abnormal Execution Rate from 69.0% to 26.7% and increases the Successful Task Completion Rate from 21.7% to 35.0%. These results demonstrate that execution guardrails learned from historical failures can substantially improve the reliability of AI coding agents while highlighting the remaining challenge of balancing safety and task completion.