ToolGate: Contract-Grounded and Verified Tool Execution for LLMs

Yanming Liu, Xinyue Peng, Jiannan Cao, Xinyi Wang, Songhang Deng, Jintao Chen, Jianwei Yin, Xuhong Zhang

TL;DR

ToolGate introduces a formal verification framework for LLM tool calling by utilizing Hoare-style contracts (preconditions and postconditions) alongside an explicit, typed symbolic state space. By gating tool execution and verifying outputs before they can modify the system's world model, ToolGate eliminates hallucinated or invalid tool steps, significantly boosting both task success rates and execution efficiency.

What Problem Does This Paper Address?

While Large Language Models (LLMs) excel at using external tools (like APIs and databases) to solve complex problems, existing tool-augmented frameworks (e.g., ReACT) rely almost entirely on implicit natural language reasoning to decide when to invoke a tool and whether to trust its output.

This lack of formal verification leads to several critical failure modes:

  1. Parametric Hallucination: LLMs frequently invent invalid arguments, such as hallucinating file IDs or directory paths.
  2. State Violations: Models attempt to call tools out of sequence, such as modifying a file before checking if it exists or securing the right permissions.
  3. Silent Failures: Tools often return a successful status code (like HTTP 200) but provide an empty or vacuous response. Without explicit verification, the LLM blindly incorporates this bad data, causing errors to propagate down the reasoning chain.

Methods

ToolGate addresses these challenges by wrapping the tool-calling process in a rigorous, mathematically grounded verification loop based on Hoare Logic.

ToolGate framework overview compared to traditional methods.

The framework consists of three core pillars:

  • Typed Symbolic State Space ($\Sigma$): Instead of relying on unstructured text memory, ToolGate maintains a structured key-value map representing trusted world facts. Every verified tool output is written here.
  • Hoare-Style Contracts: Every tool $t$ is formalized with a contract consisting of a precondition ($P_t$) and a postcondition ($Q_t$): {Pt} t {Qt}.
  • Preconditions act as a static firewall. Before a tool is executed, ToolGate checks if the current symbolic state satisfies $P_t$. If it doesn't, the tool is blocked.
  • Postconditions act as a runtime safety gate. Once a tool returns a result, $Q_t$ verifies its structural validity, type correctness, and semantic consistency before allowing it to update the global state.
  • Contract-Governed Policy: ToolGate integrates these logical constraints directly into the LLM's probabilistic sampling process. The ranking distribution of candidate tools is dynamically filtered and renormalized based on whether their preconditions are met, ensuring the model's trajectory stays within a valid solution space.

Datasets

The authors evaluated ToolGate using two prominent benchmarks:

  1. ToolBench: A massive dataset containing over 16,000 real RESTful APIs organized into 49 functional categories, used to test local tool invocation and global planning.
  2. MCP-Universe: A benchmark that connects to real, running Model Context Protocol servers. It features 231 task instances across 6 complex real-world domains, including Location Navigation, Repository Management, and Financial Analysis.

Key Insights and Ideas

  • Formal Logic Beats Pure Heuristics: Rather than letting an LLM "trial-and-error" its way through thousands of APIs, applying strict logical constraints to prune the search tree prevents the model from wandering down doomed execution paths.
  • Postconditions are the Real Gatekeepers: The authors' ablation study revealed that omitting postcondition checks ($\{Q\}$) degraded performance far more than omitting precondition checks ($\{P\}$). On GPT-5.2, removing $\{Q\}$ checks caused the average success rate to drop by 10.8%, compared to a 4.5% drop when $\{P\}$ checks were skipped. This highlights how vulnerable LLMs are to "silent failures" where an API technically succeeds but returns empty or misaligned data.
  • A Closed-Loop System: Preconditions optimize efficiency by statically pruning invalid paths, while postconditions guarantee correctness by dynamically rectifying logical drift through backtracking.

Key Results

ToolGate was tested across several state-of-the-art LLM backbones (including GPT-5.2, DeepSeek V3.2, Qwen-3-235B, and Gemini 3 Pro) and consistently outperformed competitive baselines like ReACT, DFSDT, and ToolChain*.

  • Higher Success Rates: Under GPT-5.2, ToolGate achieved a substantial performance leap, reaching pass rates of 85.5% / 93.0% / 91.8% on ToolBench G1/G2/G3 tasks, outperforming the strongest baseline (ToolChain*) by 4–6% in Win Rate.
  • Fewer Wasted Steps: By collapsing invalid search branches, ToolGate drastically reduced the number of tool-calling steps required to complete a task. For example, with GPT-5.2, the average number of calling steps dropped from 6.78 to 4.21—a 37.9% improvement in efficiency.
Comparison of Average Tool-Calling Steps in Tool-Bench showing ToolGate's efficiency.
  • High Interception Precision: In the complex MCP-Universe benchmark, ToolGate's verification layer intercepted 29.4% of all tool-calling requests (17.6% caught by preconditions due to hallucinations/state violations; 11.8% caught by postconditions due to empty or misaligned results), successfully preventing cascading errors.

Limitations and Future Work

While ToolGate marks a major step toward reliable agentic workflows, the authors note several limitations:

  • Scope Constraints: The current framework is restricted to text-based and structured data interactions. Extending it to multi-modal tools and long-chain, multi-step collaborative tasks remains future work.
  • Static Evaluation Environments: The benchmarks used do not fully simulate real-world API volatility, such as network latency, rate limits, or rapidly fluctuating data states.
  • Prompt Bias: The strategies optimized for specific models might not perfectly generalize across the entire open-source LLM landscape.

Summary updated

BibTeX
@inproceedings{liu2026toolgate,
  author = {Yanming Liu and Xinyue Peng and Jiannan Cao and Xinyi Wang and Songhang Deng and Jintao Chen and Jianwei Yin and Xuhong Zhang},
  title = {{ToolGate: Contract-Grounded and Verified Tool Execution for LLMs}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2026},
  doi = {10.18653/v1/2026.findings-acl.470},
}
Figure