NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

AutoFeedback: An LLM-based Framework for Efficient and Accurate API Request Generation

Huanxi Liu, Jiaqi Liao, Dawei Feng, Kele Xu, Huaimin WangarXiv 2024 · DOI

Introduction

Large Language Models (LLMs) have demonstrated remarkable capabilities in understanding human intent. However, translating this intent into the rigid, precise syntax required by external APIs remains a significant challenge. This often results in "hallucinations," where models invent non-existent APIs, use incorrect parameter names, or provide data in invalid formats. Existing feedback mechanisms typically rely on generic error messages, which lack the factual grounding necessary for the LLM to correct its mistakes effectively.

The AutoFeedback Framework

To address these challenges, we present AutoFeedback, a novel framework designed to minimize API call hallucinations through grounded, fine-grained feedback loops. The framework consists of two primary components:

  1. Static Scanning Component (SSC): This component performs local validation before a request is sent to the server. By comparing the generated request against retrieved API documentation, the SSC identifies syntax and naming errors (categorized as E1: Format, E2: Name Mismatch, E3: Invalid Parameter, E4: Input Mismatch). These identified "pseudo-facts" are then fed back to the LLM to re-ground its generation process.
  2. Dynamic Analysis Component (DAC): When a request passes static checks but fails during server-side execution, the DAC intervenes. It utilizes Retrieval-Augmented Generation (RAG) to interpret cryptic server error codes by searching the documentation for specific explanations, providing the LLM with actionable guidance for its next attempt.
Figure 1: The AutoFeedback workflow, illustrating the interaction between the LLM, the API documentation, and the server feedback loop.

Experimental Setup

The effectiveness of AutoFeedback was evaluated across four diverse datasets to test robustness across different domains and languages:

  • API-Bank: A large-scale synthetic dataset for tool-use.
  • MP-API: A specialized materials science dataset featuring Chinese instructions.
  • ToolAlpaca-single: Real-world scenarios decomposed into single-step tasks.
  • ToolAlpaca-mix: Complex, multi-step API planning tasks.

Results and Analysis

AutoFeedback significantly outperforms baseline LLM performance across all tested models and datasets.

Accuracy and Error Reduction

The framework achieved near-perfect accuracy in several scenarios. For instance, GPT-4 Turbo's accuracy on the ToolAlpaca-single dataset improved from 84.48% to 100%. Smaller models like LLaMA-2-7B also saw substantial gains, jumping from approximately 34% to 75% accuracy. As shown in the error distribution analysis, the framework effectively reduces specific error types, particularly naming mismatches and invalid parameters.

Figure 2: Distribution of error types (E1-E4) across different LLMs and datasets, demonstrating the reduction in hallucinations.

Efficiency and Cost

Despite the increased token usage per prompt due to documentation snippets, AutoFeedback reduces the total interaction cost. By enabling the model to reach the correct answer in fewer iterations, the "overhead per 1% accuracy improvement" decreased by 11% to 23% for GPT-based models. This demonstrates that granularity in feedback is not just more accurate, but more economical.

Conclusion

AutoFeedback demonstrates that fine-grained, grounded feedback is essential for reliable tool use in LLMs. By combining static syntax checks with dynamic, documentation-based error analysis, the framework provides a robust solution to the API hallucination problem. Future work will focus on improving retrieval accuracy and implementing more advanced loop detection for complex multi-step tasks.

Summary updated

BibTeX
@misc{liu2024autofeedback,
  author = {Huanxi Liu and Jiaqi Liao and Dawei Feng and Kele Xu and Huaimin Wang},
  title = {{AutoFeedback: An LLM-based Framework for Efficient and Accurate API Request Generation}},
  year = {2024},
  eprint = {2410.06943},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.06943},
}
Figure