GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
ICSE 2026

AgentSpec: Customizable Runtime Enforcement for Safe and Reliable LLM Agents

Write safety rules as trigger, check and enforce, and run them before every agent step. Hand-written rules stopped most risky actions in milliseconds; rules written by an LLM were patchier.

Breakdown by FDE Interviews · 13 min read · Updated

About the original · 2025
AUTHORS
Wang, Poskitt, Sun
FROM
Singapore Management University
PUBLISHED
Mar 2025 · ICSE 2026
CITED BY
294Semantic Scholar · Oct 2026
IN THIS BREAKDOWN · 10 SECTIONS

You can read 18% of this breakdown.

01

The paper in one minute

An agent that can run code, move a robot arm or steer a car will sometimes try something it should not, either because it was asked to or because it misjudged. Whether an action is acceptable often depends on who is deploying it: a bank wants approval before any transfer to a new payee, a research lab might not. Haoyu Wang, Christopher Poskitt and Jun Sun at Singapore Management University propose a way to write those organization-specific rules down and enforce them while the agent runs.

AgentSpec is a small domain-specific language. Each rule has a trigger, the event that makes it relevant (the agent is about to run Python, a pedestrian appears); checks, predicates that must all be true for the rule to fire (the code fetches from an untrusted site and prints the result); and an enforcement, what happens then (stop, pause for user inspection, run a predefined corrective action, or make the model re-examine its plan). The runtime hooks into the agent framework's loop, LangChain in the implementation, at three points: before an action, after its observation, and when the agent declares it is finished.

The authors wrote rules for three very different agents: a code-executing agent tested on RedCode-Exec, an embodied household agent on SafeAgentBench, and an autonomous-driving agent on the Apollo stack with traffic-law scenarios from FixDrive. Hand-written rules stopped most risky behavior with negligible overhead. They also asked OpenAI's o1 to write rules from a few examples, which worked partly: the generated rules caught most cases similar to their examples and missed others.

THE IDEA, VISUALLY
A RULE: TRIGGER, CHECK, ENFORCE rule @inspect_print_untrusted_source trigger PythonREPL check request_untrusted_source write_to_io enforce user_inspection end fires before the action runs all predicates must be true what happens then ENFORCEMENT OPTIONS stop end the task user_inspection pause and ask invoke_action run a set fix llm_self_examine model reconsiders Rules parse in about 1.4 ms; checks take 1 to 3 ms, against agent runs of 10 to 25 seconds. HAND-WRITTEN VS LLM-WRITTEN RULES share of risky cases stopped, by domain Code agent (RedCode-Exec) hand-written: 333 of 364 attempts 87.3% o1 rules: 87.3% of risky code Embodied agent (SafeAgentBench) hand-written: all hazardous actions 95.6% o1 rules: 95.6%; 71.0% on safe twins Autonomous driving (FixDrive) hand-written: 8 of 8 scenarios 62.5% o1 rules: 5 of 8, zero-shot Code-agent tests used only risky instructions, so false alarms on ordinary code were not measured. LLM-written rules generalized mostly to the examples they were shown.
AgentSpec rules intercept an agent before each action and apply a stop, an approval or a correction when their checks hold. Hand-written rules covered the test sets well; rules generated by an LLM missed cases outside their examples.
Research notes: the problem, approach and results
333 / 422

attempts to run risky code that hand-written rules flagged; 91.5% once two non-risky categories are excluded

5 of 8

law-breaking driving scenarios prevented by o1-written rules, against 8 of 8 for hand-written rules

1–3 ms

to evaluate a rule's checks, against 10 to 25 seconds for an agent run

THE PROBLEM

Agents act in code shells, robots and cars, and what counts as unsafe depends on the organization. Model-based safeguards are opaque and can be talked around; existing rule systems are rigid or tied to one agent.

THE IDEA

A small language for rules with a trigger (an action or event), checks (predicates that must all hold) and an enforcement (stop, ask the user, run a fixed action, or make the model reconsider), hooked into the agent loop before each step.

THE RESULT

Hand-written rules flagged 91.5% of risky code runs where the agent actually wrote risky code, removed all hazardous robot actions and prevented all 8 traffic-law violations, for 1 to 3 milliseconds per check. Rules written by OpenAI o1 did worse, especially beyond their examples.

02

Why it matters to an FDE

Customers come with policies: transfers above a limit need approval, production systems are read-only, personal data never leaves the region. Telling the model those rules in a prompt gives you a hope. Enforcing them in the loop, before the action executes, gives you a control you can show an auditor.

Put the customer's rules in code at the action boundary. Each rule names the action it watches, the exact conditions, and the response. That is reviewable by the customer's risk team in a way a system prompt is not.

Choose the enforcement per risk. Stop for things that must never happen, approval for things that are sometimes fine, a corrective action where a safe alternative exists. A rule that always stops will be disabled the first week.

Write predicates about effects, not spelling. A check for the string "rm" misses three other ways to delete a directory and blocks routine cleanup. Check what the action does: which paths, which accounts, which amounts.

Do not trust generated rules without tests. Rules written by an LLM from examples generalized mostly to cases like those examples. Have people review them, and test them against both risky and harmless actions.

It is cheap. Rule checks took milliseconds next to agent runs of tens of seconds, so there is no performance argument against them.

THE FULL BREAKDOWN

Understand the mechanism. Try it on a real problem.

Unlock this breakdown and 99 more papers.

Premium opens every paper in full, plus every answer, concept, course and guide on the site. One payment for six months of access.

6 months · One payment · No auto-renewal

Get Premium · ₹2,000 / $25
  • ◇1 architecture diagram
  • </>1 runnable code experiment
  • ▦3 results tables
  • ?5 interview questions with answers
  1. 03Key takeaways

    The language, its semantics, each domain's result, generated rules, and the misreadings to avoid

    Free account
  2. 04How it works

    The rule semantics, the hooks into an agent loop, predicates, and generated rules

    Premium
  3. 05The numbers that matter

    The code results category by category, the generated-rule results, and what was not measured

    Premium
  4. 06Try it yourself

    Recount the paper's code results, then see why predicates must describe effects, not strings

    Premium
  5. 07Where it breaks

    The limits of rule-based enforcement and of this evaluation

    Premium
  6. 08Using it on a deployment

    Turning a customer's policies into runtime rules that hold up

    Premium
  7. 09Interview angles

    Five questions this paper prepares you for, with answer hints

    Premium
Back to the paper library →