Skip to content

AutoSpec: Safety Rule Evolution for LLM Agents Based on Inductive Logic ProgrammingAutoSpec: Safety Rule Evolution for LLM Agents via Inductive Logic Programming

arXiv· arXiv:2606.24245· Pingchuan Ma, Zhaoyu Wang, Zimo Ji, Yuguang Zhou, Zhantong Xue, Zongjie Li, Shuai Wang, Xiaoqin ZhangZhejiang University of Technology; HKUSTIndexed by this site · 13 days ago· Originally publishedDefenses

Quick read

Defenses

Based on the paper PDF (AI-generated); refer to the original

The authors propose AutoSpec, which uses ILP-guided CEGIS to evolve the safety rules of deployed LLM agents from user annotations, raising rule F1 to 0.98 and 0.93 on 291 traces across two domains.

Threat modelDefender's perspective: deployed LLM agents carry expert-written symbolic safety rules (AgentSpec guardrails), but updates to models, tools and prompts cause rule drift, resulting in rules that are too conservative (high FP) or too permissive (high FN). Defenders can obtain user/reviewer safe/unsafe annotations on traces and use these annotations as counterexamples to automatically evolve rules while maintaining interpretability.

Questions
Deployed LLM agents rely on expert-written safety rules to block dangerous operations, but continuous updates to models and tools cause static rules to drift: too strict means false positives, too permissive means false negatives; neural classifiers are adaptive but not interpretable. The authors want to automatically turn safe/unsafe annotations accumulated during operation into updates to existing rules.
Methods
AutoSpec formalizes rule maintenance as ILP-guided CEGIS: evaluate the current rules on annotated traces, mine FP/FN counterexamples, use the ILP solver ILASP to learn predicates that can distinguish the counterexamples, then use four edit operators to generate candidate rules and validate and select the best on the full dataset, iterating until convergence.
Experiments and results
In the two domains of code execution (191 traces) and embodied agents (100 traces), AutoSpec's held-out F1 is 0.980 and 0.933 respectively, higher than the expert rule baselines (0.698, 0.493) and LLM classifiers (0.813, 0.881); removing ILP drops the code-domain F1 to 0.203; 10 practitioners preferred AutoSpec on all three dimensions of interpretability, actionability and trust.
Limitations and future work
The authors note: the evaluation covers only the two domains of code execution and embodied agents, while other agents such as web and database agents remain to be explored; the safety traces in the code domain were generated as mirrored RedCode categories; labels depend on human annotation; global optimality is not guaranteed, and rule quality depends on the richness of the predicate library; trigger rewriting and temporal operators (such as LTL) are left for future work.
Experimental setupAutoSpec · RedCode-Exec、SafeAgentBench · Precision、Recall et al.
Evaluated models
AutoSpec
Benchmarks
RedCode-ExecSafeAgentBench
Metrics
PrecisionRecallF1FP/FNconvergence iterationsrule complexitycandidate efficiency
AI summaryAutoSpec automatically evolves expert safety rules for LLM agents from user safe/unsafe annotations via inductive logic programming (ILP). It uses counterexample-guided inductive synthesis (CEGIS) to iteratively mine false-positive and false-negative counterexamples, generating and validating candidate rule modifications. On 291 execution traces in the code execution and embodied agent domains, rule F1 improved to 0.98 and 0.93, false positives were reduced by up to 94%, and F1 reached up to 4.8 times that of heuristic CEGIS.

AutoSpec automatically evolves expert safety rules for LLM agents from user safe/unsafe annotations via inductive logic programming (ILP). It uses counterexample-guided inductive synthesis (CEGIS) to iteratively mine false-positive and false-negative counterexamples, generating and validating candidate rule modifications. On 291 execution traces in the code execution and embodied agent domains, rule F1 improved to 0.98 and 0.93, false positives were reduced by up to 94%, and F1 reached up to 4.8 times that of heuristic CEGIS.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    How to make the safety rules of deployed LLM agents automatically evolve as the environment changes, while preserving interpretability.

    Core problem: deployed expert safety rules are static, while agent environments keep changing; how can these rules be automatically evolved using safe/unsafe annotations accumulated during operation while preserving rule interpretability.

    • Problem setting and importance: LLM agents can execute code, operate files and control robots, and their autonomy brings safety risks (the authors' example: an agent cleaning up temporary files may execute a destructive delete command). The authors argue that pre-deployment validation is infeasible and that new failure modes will emerge during deployment.
    • Shortcomings of existing methods (as stated in the paper): static rules involve a precision-recall trade-off—too conservative means high FP that disrupts normal workflows, too permissive means high FN that misses new risks; neural classifiers are black boxes and cannot explain why something was blocked, making them unsuitable for safety-critical deployments that require auditability. Neither approach turns accumulated annotations into automatic updates to existing expert rules.
    • Core observation: while an agent runs, users and reviewers approve/reject borderline tool calls, forming a stream of labeled execution traces; these annotations are naturally counterexamples in CEGIS—unsafe actions the rules let through or safe actions they blocked are exactly where the rules disagree with ground truth.
    • Paper's proposed approach: AutoSpec, a framework that formalizes rule maintenance as ILP-guided CEGIS: mine counterexamples, use ILP to learn distinguishing predicates, generate candidate rule edits, validate and select the best, iterate until convergence, and output readable, auditable rules.
    • Threat model (defender's perspective):
      • Protected objects: LLM agents with tool-calling capabilities (the two domains of code execution and embodied home robots).
      • Risks: the agent executes destructive commands, leaks sensitive data, or violates domain constraints; risks often arise from combinations of actions rather than a single action.
      • Defender's capabilities: access to user/reviewer safe/unsafe annotations at trace granularity, and to structured tool-call traces recorded by the agent framework.
      • Defense position: the rule enforcement layer (Layer 1) in defense-in-depth, complementary to layers such as neural guardrails and sandboxes (Figure 2).
  2. What related research exists?

    Related work falls into three groups: LLM agent static defenses, program synthesis and rule learning, and runtime verification; the authors claim AutoSpec is the first safety-rule evolution tool.

    LLM agent safety defenses

    • Symbolic rules and runtime monitoring: AgentSpec (Wang et al., 2025) provides a customizable runtime rule-enforcement DSL; AutoSpec's constraints are encoded in AgentSpec; ProbGuard (Wang et al., 2025) performs probabilistic runtime monitoring. The paper points out that such defenses are written statically and do not improve from observed behavior.
    • Neural classifiers and LLM judges: Llama Guard (Inan et al., 2023) and others use classifiers or LLMs to judge safety; the paper criticizes their black-box decisions as uninterpretable and non-actionable.
    • Permission control and multi-layer guardrails: ProGent (Shi et al., 2025) and others perform permission/access control, and the Swiss cheese model (Shamsujjoha et al., 2025) gives a multi-layer guardrail architecture; there are also testing and red-teaming tools (Perez et al., 2022, etc.). The authors state that the failures exposed by these works (e.g., red-team traces) can enter AutoSpec's loop as counterexamples, and the two are complementary.

    Program synthesis, rule learning, and formal methods

    • CEGIS and SyGuS: CEGIS (Solar-Lezama et al., 2006; Jha et al., 2010) synthesizes programs from specifications, and SyGuS (Alur et al., 2013) adds syntax-guided search; the paper points out that prior CEGIS relies on heuristic search (Pu et al., 2018), exploring the edit space uniformly, with slow convergence and suboptimal rules.
    • ILP and rule learning: ILP systems Progol, FOIL, Aleph, and ILASP learn logic programs from examples; RIPPER and CN2 learn if-then rules from labeled data. AutoSpec uses ILASP to learn discriminative predicates to guide the loop, rather than synthesizing rules from scratch.
    • Runtime verification: Leucker & Schallhart (2009) and others monitor executions against temporal specifications (LTL, MTL); AutoSpec instead evolves a set of runtime-executable rules, with temporal extension left as future work.

    Baselines and benchmarks

    • Baseline methods: B1 expert-written AgentSpec guardrails (also the evolution starting point), B2 an LLM classifier with few-shot examples from the same annotations, B3 CEGIS without ILP (ranking predicates by coverage), B4 random search (§5.4).
    • Benchmarks/datasets: the code-execution domain uses unsafe traces from RedCode-Exec (Guo et al., 2024) plus safe traces generated by GPT-5.1-Codex; the embodied domain uses AI2-THOR traces from SafeAgentBench (Yin et al., 2024) (§5.2).

    Author positioning: to their knowledge, AutoSpec is the first safety-rule evolution tool (the authors call it "the first safety-evolution tool"), complementary to static defenses, turning rule maintenance from one-time manual writing into a continuous, annotation-driven evolution problem.

  3. How does the paper address this problem?

    AutoSpec formalizes rule evolution as discrete optimization, using a four-stage ILP-guided CEGIS loop to iteratively edit rules until convergence.

    Overall approach: starting from expert rules, treating user annotations as counterexamples, iteratively edit the rules with an ILP-guided CEGIS loop—counterexamples locate the failure, ILP finds the most discriminative predicates, restricted edit operators turn the predicates into verifiable candidate rules, and greedy ascent guarantees monotonic improvement.

    Problem formalization

    • Rule evolution problem (Def. 3.1): given an initial rule set R0, an annotated trace set D, and a predicate library P, find R∗ = argmaxR ∈ Edit∗(R0,P) S(R), i.e., the rule set reachable via edit operators that maximizes the validation score S; the search space grows exponentially with the number of predicates and cannot be exhaustively enumerated.
    • Two-level structure: rules trigger at the event level (Def. 2.2), trace safety is determined by whether any rule triggers (Def. 2.4), and annotations are given at the trace level; AutoSpec bridges the two levels by recording in the ILP encoding which predicates hold at each event.
    • Predicate library: a cross-domain predicate library P, where each predicate is a Boolean function on events; evaluation uses 16–24 predicates per domain (Table 1 gives examples; the full list is in the supplementary material).

    Counterexample mining (§4.1)

    • Replay traces on D to evaluate the current rule set, obtaining precision, recall, and F1; misclassified traces are counterexamples.
    • Repair direction: FN (missed unsafe traces) means the rule is too narrow and needs relaxing; FP (falsely flagged safe traces) means it is too broad and needs tightening; each counterexample records the triggered rule and the failing predicate.

    Edit operators (§4.2)

    • A rule is a pair of a trigger g and a conjunctive predicate body ϕ; four operators (Table 2): AddConjunct (add a conjunct), AddException (add an exception ¬p), Relax (delete a literal), AddDisjunct (add a new branch at the rule-set level).
    • The operators only change ϕ or the rule set; the trigger is fixed (the authors state the trigger is determined by the tool being protected and is not a source of error; rewriting triggers is left as future work).

    ILP predicate learning and candidate generation (§4.3, §4.4)

    • ILP task: FNs as positive examples and FPs as negative examples, using ILASP to learn the minimal predicate combination H = (p11 ∧ p12 ∧ ⋯) ∨ ⋯ ∨ (pk1 ∧ ⋯), i.e., the minimal predicate disjunction that covers all positives and no negatives; the predicates in H are the discriminative predicates.
    • Suggestion scoring and filtering: score suggestions by "newly covered FNs minus newly violated FPs", and keep a small diverse set of suggestions via greedy set cover with a quota.
    • Three candidate-generation strategies: single-step editing, mixed repair chains (precision edits plus recall edits), and failure-driven branching (adding high-precision disjunctive branches for residual FNs); candidates are validated on D and selected greedily by the lexicographic order S(R') = (F1, Prec, −U, −|R'|).

    Convergence and implementation (§4.5, §5.6)

    • Termination conditions: reaching the target score threshold, no candidate can improve, or the iteration budget K is exhausted; predicates already in the rules are down-weighted (soft novelty pressure) to prevent oscillation.
    • Properties: terminates in finite time, score is monotonically non-decreasing, locally optimal at termination, deterministic output; the authors explicitly do not guarantee global optimality (the underlying synthesis problem is NP-hard), and rule quality depends on the richness of the predicate library.
    • Implementation: Python 3.10, 12K lines of code, based on the AgentSpec predicate library; ILASP v4.4.1 as the ILP backend, with a 120-second timeout per learning task; experiments run on a MacBook Pro (M2 Max, 32 GB RAM).
  4. What experiments did the paper conduct?

    On 291 traces across two domains, AutoSpec achieves held-out F1 of 0.980/0.933, outperforming expert rules, the LLM classifier, and ablation variants.

    Experimental setup

    • Data: 291 manually annotated traces in total. Code-execution domain: 191 traces, of which 91 unsafe traces are taken from RedCode-Exec (25 risk categories, at most 4 per category) and 100 safe traces are generated by GPT-5.1-Codex; traces are 1–9 events long (mean 1.4). Embodied domain: 100 traces (52% unsafe) taken from SafeAgentBench (AI2-THOR simulated home robot), with the agent using zero-shot ReAct prompting with GPT-5.1-Codex, and traces 1–15 events long (mean 5.1) (§5.2).
    • Baselines: B1 expert AgentSpec guardrails (also the evolution starting point), B2 LLM classifier (5 few-shot examples per category), B3 CEGIS without ILP, B4 random search (§5.4).
    • Metrics: trace-level precision, recall, F1, FP/FN, plus number of iterations to convergence, rule complexity, and candidate efficiency (§5.3).
    • Evaluation protocol (§5.5): RQ1 evolves on the seed split and evaluates on the held-out split; RQ2 reports in-sample convergence trajectories on the refinement set (the code domain starts from a minimal single-predicate rule, so F1≈0 at iteration 0); RQ3 uses a 70%/30% initial/incoming task split to test generalization.
    • User study: 10 practitioners with more than one year of ML system development or deployment experience, 4 scenarios, 5-point Likert scale rating three dimensions (§6.3.2).
    • The paper does not report the number of repetitions for the RQ1/RQ2 experiments.

    Main results

    Table 3: classification performance of each method on the held-out test sets in the two domains.

    Swipe horizontally to read the table

    MethodCode execution P/R/F1Code FP/FNEmbodied P/R/F1Embodied FP/FN
    B1 expert rules0.544 / 0.974 / 0.69831/11.000 / 0.327 / 0.4930/35
    B2 LLM classifier1.000 / 0.684 / 0.8130/120.842 / 0.923 / 0.8819/4
    B3 CEGIS w/o ILP1.000 / 0.316 / 0.4800/261.000 / 0.500 / 0.6670/26
    B4 random search0.536 / 0.974 / 0.69232/11.000 / 0.327 / 0.4930/35
    AutoSpec0.960 / 1.000 / 0.9802/00.925 / 0.942 / 0.9334/3
    • The authors state that AutoSpec achieves the highest F1 in both domains; B1 exhibits opposite failure modes (too broad in the code domain, too narrow in the embodied domain), reflecting the precision-recall trade-off of static rules.
    • Negative results/exceptions: B3's held-out F1 in the code domain (0.480) is lower than the un-evolved B1 (0.698); per the §5.5 protocol, the authors explain this as a generalization gap from B3 overfitting the seed split, and that it does not violate the algorithm's monotonicity guarantee.
    • The authors state that B2's black-box decisions limit interpretability and actionability; B4 is comparable to B1, indicating that guided search is necessary.

    RQ2: Convergence and the role of ILP

    • Convergence trajectories (Figure 4): the code domain reaches the target threshold of 0.95 within 4 iterations, with a final F1 of 0.980, rising from 0.000 to 0.815 in the first iteration; the embodied domain rises from 0.493 to 0.933 over 5 iterations (0.493 → 0.771 → 0.835 → 0.870 → 0.885 → 0.933), terminating because the iteration budget was exhausted rather than reaching the threshold, and the authors believe more iterations might improve further.
    • ILP vs heuristic (Table 4, in-sample): code domain ILP version F1 0.980 (4 iterations, 319 candidates, 20.1s) vs heuristic 0.203 (2 iterations, 197 candidates, 4.4s), which the authors state is a 382% improvement; embodied domain 0.933 (5 iterations, 600 candidates, 11.8s) vs 0.758 (4 iterations, 372 candidates, 4.3s), which the authors state is a 23% improvement.
    • Authors' interpretation: the heuristic terminates after 2 iterations in the code domain because it cannot find improving candidates; ILP explores more candidates but more targeted ones; the time cost is acceptable because AutoSpec can run asynchronously with agent execution.

    RQ3: Generalization and usability

    • Generalization (Figure 5): rules are learned on 70% initial tasks and tested on 30% incoming tasks. Code domain F1 goes from 0.973 (initial) to 0.957 (incoming), a gap of 1.6 percentage points, with precision 1.000 and recall 0.917 on incoming; embodied domain F1 goes from 0.889 to 0.842, a gap of 4.7 percentage points, with precision 0.800 and recall 0.889 on incoming.
    • User study (Figure 6): AutoSpec rules score higher than the LLM classifier on all three dimensions—interpretability (4.97 vs 3.45), actionability (4.83 vs 2.73), and trust (4.80 vs 2.77) (Wilcoxon signed-rank test, p < 0.01); of 120 pairwise comparisons, 101 (84.2%) preferred AutoSpec, and the remaining 19 were ties.
    • Authors' interpretation: the gaps in actionability and trust (both over 2 points) are larger than the interpretability gap (1.5), and practitioners can understand the LLM's reasons but do not dare to modify or deploy based on them.

    Other ablations and analyses

    • Removing ILP (Table 5, code domain): F1 drops from 0.98 to 0.20, iterations 4→2, candidates 319→197.
    • Removing the failure-driven branch: F1 0.97, iterations 4→6, candidates 319→677 (the authors state candidate evaluations increase by 112%).
    • Removing multi-step editing: F1 drops to 0.72, iterations 4→10, candidates 300.
    • Authors' interpretation: ILP is the most critical component; multi-step editing handles counterexamples that require coordinated modification across rule components; the failure-driven branch mainly improves efficiency.
  5. What are some points that can be further explored?

    The authors list directions such as domain coverage and temporal extension; the experiments cover 291 traces across two domains and a 10-person user study.

    Limitations and future directions noted by the authors

    • Domain coverage: the evaluation spans the two domains of code execution and embodied agents; the authors state that other scenarios such as web and database agents "remain to be explored" (§7 Threats to validity).
    • Data construction: the safety traces in the code domain are benign counterparts mirroring RedCode unsafe categories, deliberately increasing FP pressure; labels depend on human annotation (§7).
    • Global optimality: the authors explicitly do not guarantee global optimality or convergence rate, and rule quality depends on the richness of the predicate library P (§4.5).
    • trigger rewriting: the current edit operators fix the trigger and only modify the rule body; operators that rewrite the trigger are "straightforward extension left to future work" (§4.2).
    • Temporal properties: predicates are evaluated on a single event and its local context, and richer native temporal operators (such as LTL) are "a natural extension" (§7).
    • Positioning statement: the authors state that AutoSpec is aimed at continuous, periodic maintenance rather than one-off offline tuning, and is expected to be used in combination with other defense layers (§3.3).

    Scope of experimental coverage

    • The evaluated objects are rule sets in two domains, totaling 291 traces: 191 code execution traces (91 unsafe + 100 safe) and 100 embodied agent traces (52% unsafe) (§5.2).
    • The comparison methods are B1 expert rules, B2 LLM classifier, B3 CEGIS without ILP, and B4 random search; the authors explicitly do not perform cross-layer comparisons (neural guardrails, sandboxes), on the grounds that this would confound orthogonal design dimensions (§5.4).
    • The traces were generated by GPT-5.1-Codex (code-domain safety traces, embodied-domain agent driving); the paper does not state the specific model used by the B2 classifier.
    • The user study has 10 practitioners, 4 scenarios and 120 pairwise comparisons (§6.3.2).
    • The paper does not report the number of repeated runs for each number in RQ1/RQ2; the convergence traces in RQ2 are sample results, and RQ1 results are under a single seed/held-out split (§5.5).
  6. Summarize the main content of the paper

    AutoSpec uses ILP-guided CEGIS to turn user annotations into automatic, interpretable evolution of expert safety rules.

    AutoSpec is a safety rule evolution framework for LLM agents, which the authors describe as the first safety rule evolution tool.

    • Problem to solve: the expert safety rules of deployed agents are static, and updates to models, tools and prompts cause rule drift, resulting in rules that are too broad (high FP) or too narrow (high FN); neural classifiers are adaptive but not interpretable. The authors' core observation is that users' approve/reject annotations of tool calls during operation are naturally counterexamples for CEGIS.
    • Method highlights: rule maintenance is formalized as ILP-guided CEGIS—evaluate rules on annotated traces, mine FP/FN counterexamples, use ILASP to learn the minimal predicate combination that distinguishes the counterexamples, then use four edit operators (AddConjunct, AddException, Relax, AddDisjunct) to generate candidates and validate and select the best on the full dataset, iterating until convergence; the authors explicitly do not guarantee global optimality.
    • Main results:
      • In the two domains of code execution (191 traces) and embodied agents (100 traces), held-out F1 is 0.980 and 0.933 respectively, higher than the expert rule baselines (0.698, 0.493) and LLM classifiers (0.813, 0.881) (Table 3).
      • The heuristic variant without ILP achieves a sample F1 of only 0.203 in the code domain (AutoSpec: 0.980), which the authors describe as a 382% improvement (Table 4).
      • Convergence in 4 iterations in the code domain and 5 in the embodied domain (Figure 4).
      • Generalization to unseen tasks: F1 0.957 on incoming tasks in the code domain and 0.842 in the embodied domain (Figure 5).
      • 10 practitioners preferred AutoSpec on interpretability, actionability and trust (e.g., actionability 4.83 vs 2.73, p < 0.01).
    • Authors' conclusions and implications: the authors argue that AutoSpec gives the symbolic guardrail layer the adaptivity of learned classifiers while maintaining determinism, zero inference cost and auditability, making it suitable for continuous maintenance in combination with other defense layers; limitations include domain coverage, dependence on human annotation and the richness of the predicate library.

Related papers

Read originalarxiv.org