FANTAstic SEquences and Where to Find Them: Faithful and Efficient API Call Generation through State-tracked Constrained Decoding and Reranking

Zhuoer Wang, Leonardo F. R. Ribeiro, Alexandros Papangelis, Rohan Mukherjee, Tzu-Yen Wang, Xinyan Zhao, Arijit Biswas, James Caverlee, Angeliki Metallinou

Introduction

As Large Language Models (LLMs) transition into "agents" capable of using external tools, the ability to generate precise API calls has become a critical requirement. However, even frontier models often fail due to unfaithfulness (hallucinating arguments), data inefficiency (high cost of fine-tuning for new APIs), and compute inefficiency (slow constrained decoding).

The FANTASE framework addresses these challenges by enforcing documentation rules directly during the decoding process. By combining State-tracked Constrained Decoding (SCD) with a lightweight Reranking model, it achieves higher accuracy and—counter-intuitively—runs up to 2.4x faster than standard decoding methods.

The FANTASE Framework

The FANTASE architecture is designed to ensure that generated API calls are both syntactically faithful to documentation and semantically aligned with user intent.

The FANTASE framework overview, illustrating the pipeline from conversation context and API documentation to constrained decoding and final reranking.

State-tracked Constrained Decoding (SCD)

The first pillar of the framework is SCD, which replaces standard token selection with a Constrained Token Search Trie (CTST). This system tracks the "state" of the API call—identifying whether the model is currently generating a package name, a function, or an argument value.

The primary innovation of SCD is its efficiency. In standard constrained decoding, the model must still perform an inference pass for every token. In SCD, if the search trie indicates that only one valid sequence of tokens exists for a given state (e.g., a specific function name), the system appends those tokens immediately. This bypasses unnecessary model calculations, leading to significant performance gains.

A comparison of regular decoding versus SCD, showing how deterministic token sequences are appended without additional LLM inference.

Discriminator-Guided Reranking

While SCD ensures the API call follows the manual (syntactic correctness), the second pillar—a lightweight RoBERTa model—ensures it actually fulfills the user's request (semantic correctness). This 125M parameter discriminator evaluates the candidate sequences generated by the LLM and reranks them. This approach proves that small, specialized models can effectively "fix" the outputs of much larger 13B parameter models by focusing on semantic alignment.

Experimental Results

FANTASE was evaluated on the DSTC8 and API Bank benchmarks, yielding several key insights:

  • Significant Accuracy Gains: On the zero-shot API Bank challenge, SCD boosted the accuracy of a 13B model by over 32%, making it competitive with GPT-3.5.
  • Superior Speed: SCD achieved a speedup of 1.5x to 2.4x compared to regular greedy and beam search decoding by skipping deterministic tokens.
  • Prompt Efficiency: Because API rules are baked into the decoder via the Trie, the system requires fewer prompt tokens to explain documentation. This reduces memory usage (KV cache) and operational costs.
  • Robustness: The framework maintained high performance even when documentation was removed from the input prompt, demonstrating that the state-tracked constraints provide a robust fallback.

Conclusion and Future Work

FANTASE demonstrates that constraints, when implemented through state-tracking, can enhance both the faithfulness and the efficiency of LLM-based agents. While currently optimized for Python-style API calls, future work will involve adapting the framework to other structured formats like JSON or SQL and testing the approach on larger frontier models.

Summary updated

BibTeX
@inproceedings{wang2024fantastic,
  author = {Zhuoer Wang and Leonardo F. R. Ribeiro and Alexandros Papangelis and Rohan Mukherjee and Tzu-Yen Wang and Xinyan Zhao and Arijit Biswas and James Caverlee and Angeliki Metallinou},
  title = {{FANTAstic SEquences and Where to Find Them: Faithful and Efficient API Call Generation through State-tracked Constrained Decoding and Reranking}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.findings-emnlp.359},
}
Figure