MENTOR: Procedural Shielding of Tool-Using LLM Agents
Organizations: Max Planck Institute for Software Systems, Kaiserslautern, Germany · TNO-ESI, Eindhoven, The Netherlands
Abstract
Tool-using LLM agents are increasingly used to automate workflows governed by procedural manuals, such as company rules for booking travel or procuring hardware. These manuals are written in natural language for humans and describe general requirements over such complex workflows. Ensuring compliance of LLM agents with these manuals is difficult, and state-of-the-art techniques use either LLM judges or manually written rules to forbid problematic tool-calls locally at runtime. This is insufficient because (i) only blocking tool calls keeps the agent clueless about how to make correct progress towards fulfilling its task, and (ii) can lead to overly conservative behavior of the agent, as tool calls might only be problematic in certain contexts. To overcome these challenges, we introduce MENTOR, which (i) additionally provides guidance for the agent to make procedural-compliant progress on the task, and (ii) ensures that this compliance is context-aware. We achieve these goals by building a novel history-dependent runtime shield that is obtained from the procedural manual via a multi-step autoformalization pipeline. At its core, MENTOR utilizes a game-based technique to ensure robustness against runtime uncertainty without over-resticting agents' behavior. This yields a formally assisted framework for procedural shielding of LLM agents that improves compliance well beyond existing methods. In particular, MENTOR lifts the compliance of shielded light-weight open-source LLMs above that of non-shielded proprietary models. Since a shield is synthesized once per manual and then serves every task, a MENTOR-shielded agent becomes a viable choice for repeatedly executed workflows, potentially reducing deployment costs when the offline construction cost is amortized over repeated tasks.
Figures & tables
| (a) MANTRA | Operations ( ) | Sneaky Sasquatch ( ) | -retail ( ) | -airline ( ) | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Guard | L3.1 | Q3 | Q3.6 | G4 | L3.1 | Q3 | Q3.6 | G4 | L3.1 | Q3 | Q3.6 | G4 | L3.1 | Q3 | Q3.6 | G4 |
| None | 0 6 4 | 45 7 | 60 7 | 51 7 | 21 6 | 33 7 | 53 8 | 23 7 | 0 5 3 | 11 4 | 21 5 | 16 5 | 20 6 | 36 7 | 52 8 | 34 7 |
| AgentSpec | 13 5 | 55 7 | 72 7 | 62 7 | 14 5 | 28 7 | 63 7 | 16 6 | 0 9 4 | 25 6 | 26 6 | 19 5 | 30 7 | 43 8 | 50 8 | 43 8 |
| Progent | 0 4 3 | 47 7 | 68 7 | 47 7 | 21 6 | 30 7 | 51 8 | 23 7 | 0 9 4 | 12 4 | 25 6 | 21 5 | 27 7 | 39 7 | 45 8 | 39 7 |
| DynaGuard | 11 5 | 21 6 | 40 7 | 28 7 | 19 6 | 30 7 | 49 8 | 19 6 | 12 4 | 23 6 | 19 5 | 19 5 | 34 7 | 34 7 | 39 7 | 27 7 |
| [][] Ours (prompt) | 36 7 | 72 7 | 66 7 | 72 7 | 35 7 | 63 7 | 70 7 | 65 7 | 16 5 | 33 6 | 33 6 | 40 7 | 41 7 | 64 7 | 64 7 | 50 8 |
Appendix figures & tables14 assets
Supplementary material from the paper’s appendix.
Appendix
| (a) Specification structure | ||
| ::= | ||
| ::= | ||
| ::= | ||
| ::= | ||
| ::= | ||
| ::= | ||
| Expression | Meaning |
|---|---|
| The latest earlier event satisfying ; if none exists, its fields are undefined ( ). | |
| , | Whether an earlier event satisfies , and the number of such events, respectively. |
| The non-null values at path from earlier events satisfying , in chronological order. | |
| Whether is neither null, an empty string, nor an empty list. | |
| The length of a string or list; zero for an unsuitable value. | |
| For a list , whether it contains an element equal to ; for a string, a case-insensitive substring test. |
| Domain | Model | None | AgentSpec | Progent | DynaGuard | Ours | Ours |
| (prompt) | (token) | ||||||
| Llama 3.1 | 0.26 0.05 | 0.34 0.06 | 0.27 0.05 | 0.20 0.05 | 0.61 0.06 | 0.58 0.06 | |
| Qwen3 | 0.62 0.06 | 0.71 0.06 | 0.66 0.06 | 0.34 0.06 | 0.80 0.05 | 0.70 0.06 | |
| Qwen3.6 | 0.72 0.06 | 0.84 0.05 | 0.75 0.06 | 0.51 0.07 | 0.79 0.05 | 0.74 0.06 | |
| Gemma 4 | 0.63 0.07 | 0.69 0.06 | 0.65 0.06 | 0.39 0.07 | 0.84 0.05 | 0.73 0.06 | |
| GPT-5.4 mini | 0.72 0.06 | – | – | – | 0.82 0.05 | – |
| Domain | Model | None | AgentSpec | Progent | DynaGuard | Ours | Ours |
| (prompt) | (token) | ||||||
| Llama 3.1 | 0.43 0.07 | 0.60 0.07 | 0.47 0.07 | 0.32 0.07 | 0.77 0.06 | 0.81 0.06 | |
| Qwen3 | 0.72 0.07 | 0.81 0.06 | 0.79 0.06 | 0.47 0.07 | 0.85 0.05 | 0.77 0.06 | |
| Qwen3.6 | 0.79 0.06 | 0.89 0.05 | 0.81 0.06 | 0.64 0.07 | 0.85 0.05 | 0.85 0.05 | |
| Gemma 4 | 0.70 0.07 | 0.74 0.06 | 0.79 0.06 | 0.49 0.07 | 0.87 0.05 | 0.83 0.06 | |
| GPT-5.4 mini | 0.81 0.06 | – | – | – | 0.85 0.05 | – |
| TSR | ||||
| Domain | Model | None | Ours | Ours |
| (prompt) | (token) | |||
| Patient intake ( ) | Llama 3.1 | 0.03 0.05 | 0.29 0.28 | 0.38 0.20 |
| Qwen3 | 0.29 0.11 | 0.61 0.04 | 0.46 0.07 | |
| Qwen3.6 | 0.90 0.07 | 1.00 0.00 | 1.00 0.00 | |
| Gemma 4 | 1.00 0.00 | 1.00 0.00 | 1.00 0.00 | |
| Domain | Model | Claude Opus 5 | Claude Sonnet | gpt-5.5 | gpt-5.6-luna | Qwen3.8 |
|---|---|---|---|---|---|---|
| Operations ( ) | Llama 3.1 | 0.38 0.06 | 0.09 0.04 | 0.47 0.07 | 0.13 0.05 | 0.11 0.05 |
| Qwen3 | 0.64 0.07 | 0.34 0.07 | 0.68 0.07 | 0.23 0.06 | 0.34 0.07 | |
| Gemma 4 | 0.75 0.06 | 0.68 0.07 | 0.79 0.06 | 0.36 0.07 | 0.55 0.07 | |
| -retail ( ) | Llama 3.1 | 0.28 0.05 | 0.25 0.06 | 0.09 0.04 | 0.16 0.05 | 0.14 0.05 |
| Qwen3 | 0.39 0.06 | 0.46 0.07 | 0.39 0.07 | 0.28 0.06 | 0.42 0.07 | |
| Gemma 4 | 0.33 0.06 | 0.32 0.06 | 0.35 0.06 | 0.30 0.06 | 0.35 0.06 |
| Domain | Model | None | AgentSpec (LLM-gen) | AgentSpec (our loop) | Ours |
|---|---|---|---|---|---|
| Operations ( ) | Llama 3.1 | 0.00 0.00 | 0.05 0.03 | 0.00 0.00 | 0.26 0.07 |
| Qwen3 | 0.28 0.07 | 0.26 0.07 | 0.19 0.06 | 0.58 0.08 | |
| Qwen3.6 | 0.60 0.08 | 0.77 0.07 | 0.77 0.07 | 0.70 0.07 | |
| Gemma 4 | 0.56 0.08 | 0.63 0.07 | 0.56 0.08 | 0.70 0.07 | |
| Sneaky Sasquatch ( ) | Llama 3.1 | 0.08 0.04 | 0.03 0.03 | 0.00 0.00 | 0.15 0.06 |
| Qwen3 | 0.44 0.08 | 0.23 0.07 | 0.41 0.08 | 0.69 0.07 |
| Sneaky Sasquatch | -retail | |||
|---|---|---|---|---|
| Labeler | Qwen3 | Gemma 4 | Qwen3 | Gemma 4 |
| gpt-4.1-mini | 0.70 0.07 | 0.62 0.07 | 0.39 0.06 | 0.33 0.06 |
| Qwen3-4B | 0.68 0.07 | 0.60 0.07 | 0.44 0.06 | 0.28 0.05 |
| Gemma 4 | 0.07 0.04 | 0.07 0.04 | 0.42 0.07 | 0.28 0.06 |
| gpt-oss | 0.02 0.02 | 0.07 0.04 | 0.35 0.06 | 0.26 0.06 |
| Prompt shield | Prompt shield | Token shield | ||
|---|---|---|---|---|
| (gpt-4.1-mini) | (gpt-4.1) | (gpt-4.1) | ||
| Domain | Model | 5 | 5 | 5 |
| Operations | Llama 3.1 | 0.28 0.07 | 0.21 0.06 | 0.38 0.07 |
| Qwen3 | 0.62 0.07 | 0.64 0.07 | 0.55 0.07 | |
| Qwen3.6 | 0.72 0.07 | 0.70 0.07 | 0.66 0.07 | |
| Gemma 4 | 0.72 0.07 | 0.77 0.06 | 0.57 0.07 |
| Domain | Model | None | Ours (gpt-4.1) | Ours (Qwen3-4B FT) |
|---|---|---|---|---|
| Operations ( ) | Llama 3.1 | 0.00 0.00 | 0.21 0.06 | 0.30 0.07 |
| Qwen3 | 0.28 0.07 | 0.64 0.07 | 0.60 0.07 | |
| Qwen3.6 | 0.62 0.07 | 0.72 0.07 | 0.72 0.07 | |
| Gemma 4 | 0.55 0.07 | 0.77 0.06 | 0.70 0.07 | |
| Sneaky Sasquatch ( ) | Llama 3.1 | 0.07 0.04 | 0.09 0.04 | 0.14 0.05 |
| Domain | Model | None | AgentSpec | Progent | DynaGuard | Ours (prompt) | Ours (token) |
|---|---|---|---|---|---|---|---|
| Operations ( ) | Llama 3.1 | 0.59 0.03 | 0.57 0.02 | 30.70 0.46 | 3.01 0.07 | 0.73 0.04 | 2.26 0.05 |
| Qwen3 | 10.00 0.67 | 9.95 0.13 | 44.31 1.29 | 13.28 0.20 | 9.58 0.55 | 10.52 0.18 | |
| Qwen3.6 | 18.96 0.82 | 25.72 2.31 | 54.21 1.85 | 65.25 5.64 | 29.12 2.98 | 23.87 2.90 | |
| Gemma 4 | 0.64 0.01 | 0.64 0.01 | 34.47 0.92 | 2.63 0.06 | 0.75 0.03 | 0.99 0.03 | |
| Sneaky Sasquatch ( ) | Llama 3.1 | 0.39 0.01 | 0.40 0.01 | 21.25 0.98 | 2.34 0.14 | 0.45 0.00 | 1.66 0.04 |
| Qwen3 | 7.52 0.69 | 8.89 0.28 | 28.77 1.08 | 10.68 0.79 | 6.72 0.22 | 10.57 1.47 |
| Domain | Model | None | AgentSpec | Progent | DynaGuard | Ours (prompt) | Ours (token) |
|---|---|---|---|---|---|---|---|
| Operations ( ) | Llama 3.1 | 4.8 0.1 | 7.4 0.3 | 5.0 0.2 | 18.1 1.1 | 8.7 0.5 | 11.0 0.3 |
| Qwen3 | 4.3 0.1 | 4.9 0.2 | 4.4 0.1 | 13.3 0.9 | 5.3 0.1 | 8.3 0.9 | |
| Qwen3.6 | 5.0 0.1 | 5.3 0.2 | 5.1 0.3 | 9.0 0.8 | 6.3 0.3 | 10.9 0.4 | |
| Gemma 4 | 5.2 0.1 | 5.2 0.0 | 5.1 0.1 | 5.3 0.2 | 6.1 0.6 | 10.5 1.0 | |
| Sneaky Sasquatch ( ) | Llama 3.1 | 8.6 1.5 | 11.8 1.1 | 8.7 1.1 | 10.8 1.1 | 9.0 0.3 | 8.8 0.6 |
| Qwen3 | 4.2 0.2 | 5.6 0.3 | 4.5 0.2 | 6.1 0.6 | 5.6 0.1 | 6.5 0.3 |
| GPT-4.1 mini | GPT-4.1 | ||||
|---|---|---|---|---|---|
| Domain | cases | cents/case | USD/domain | cents/case | USD/domain |
| Operations | 47 | 0.06 | 0.029 | 0.30 | 0.143 |
| Sneaky Sasquatch | 43 | 0.07 | 0.030 | 0.35 | 0.150 |
| -retail | 57 | 0.25 | 0.141 | 1.24 | 0.705 |
| -airline | 44 | 0.20 | 0.086 | 0.97 | 0.429 |
LLM Guardrails
Large language model guardrails detect or constrain harmful outputs, prompt attacks, and unsafe agent actions before they cause harm.
See all 194 papers