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

Improving Large Language Models Function Calling and Interpretability via Guided-Structured Templates

Hong Dang, Tianyi Liu, Zhuofeng Wu, Jingfeng Yang, Haoming Jiang, Jun Yang, Pei Chen, Zhengyang Wang, Helen Wang, Huasheng Li, Bing Yin, Meng Jiang2025

Abstract

While Large Language Models (LLMs) are increasingly deployed as agents capable of interacting with external tools, their reliability in function calling remains a significant hurdle. Standard reasoning techniques, such as free-form Chain-of-Thought (CoT), often fail to provide the necessary structure for complex API interactions and can even degrade performance in models optimized for direct execution. This paper introduces a structured, template-based reasoning framework designed to guide models through a deliberate seven-step curriculum before executing a tool. By implementing this framework through both inference-time prompting and supervised fine-tuning (SFT), we demonstrate significant improvements in function-calling accuracy, robustness, and interpretability across a range of open- and closed-source models.

Introduction

As LLM agents move from simple text generation to active interaction with external APIs, functional correctness is paramount. However, models frequently stumble due to incorrect parameter formatting, hallucinated arguments, or the selection of inappropriate tools. A further complication is the "black box" nature of many function-calling models; they often output a call without providing the underlying rationale, making debugging and human oversight difficult.

While Chain-of-Thought (CoT) prompting has proven effective for general reasoning tasks, it is often insufficient for the highly structured requirements of function calling. In some cases, unstructured CoT can even interfere with a model's learned execution patterns. This research addresses these challenges by proposing a domain-adapted scaffolding that forces models to follow a specific reasoning curriculum, ensuring both accuracy and transparency.

Methodology: Template-Based Curricula

The core of the proposed approach is a Template-Based Curricula framework. This framework requires the LLM to navigate a specific seven-step reasoning structure prior to generating a function call. These steps are designed to mirror human problem-solving logic:

  1. Identify Functions: List the available tools.
  2. Check Relevance: Determine if the tools match the user's intent.
  3. Examine Documentation: Review the specific requirements for the chosen tool.
  4. Extract/Validate Parameters: Identify necessary arguments from the user query.
  5. Convert Types: Ensure parameters match the required schema (e.g., string to integer).
  6. Draft the Call: Create a preliminary version of the function call.
  7. Revalidate: Perform a final check against the documentation before outputting the final result.

Implementation Strategies

The authors explore two primary methods for applying this framework:

  • Template Prompting: The structured curriculum is injected directly into the system prompt at inference time, providing a zero-shot guide for the model.
  • Supervised Fine-Tuning (SFT): To internalize this behavior, the authors developed ToolGT, a synthetic dataset of 10,830 high-quality samples. Using GPT-4o-mini as a teacher model, they generated structured reasoning chains for existing function-calling data. These were validated using Abstract Syntax Tree (AST) matching and LLM-as-a-judge techniques. Open-source models, including LLaMA-3, Mistral, and Qwen, were then fine-tuned on this data to natively adopt the structured reasoning format.

Experimental Setup

The framework was evaluated using two primary benchmarks:

  • BFCLv2 (Berkeley Function Calling Leaderboard v2): Specifically the non-executable subset to ensure consistent evaluation without rate-limit interference.
  • Nexus (NexusRaven-V2): A benchmark focused on complex tool-use scenarios.

Training was conducted using a subset of 11,300 conversations from the ToolACE dataset, which served as the foundation for the structured ToolGT dataset.

Key Results and Discussion

The "CoT Tax" and the Benefit of Structure

A significant finding was that free-form CoT can actually harm performance in models already optimized for direct function calling. For example, Qwen-2.5-14B-Instruct saw a performance drop when using standard CoT compared to no reasoning at all. However, the structured templates preserved or improved performance while providing the necessary interpretability.

The Necessity of Fine-Tuning for Smaller Models

Smaller models, such as Mistral-7B, struggled to follow complex reasoning templates through prompting alone, often failing due to formatting errors. However, after supervised fine-tuning on the ToolGT dataset, their performance improved dramatically. This suggests that while large models can adapt to structure via prompting, smaller models require dedicated training to master structured reasoning formats.

Performance Gains

  • Prompting: Template-prompting outperformed standard CoT-prompting by an average of +2.8 points on BFCLv2 and +1.7 points on Nexus. Notably, LLaMA-3-70B-Instruct improved from a baseline of 70.89 (No Thought) to 77.78 (Template Prompting) on BFCLv2.
  • Fine-Tuning: Template-based SFT yielded average improvements of +1.0 on BFCLv2 and +1.3 on Nexus over models trained on standard CoT. The fine-tuned Qwen-2.5-14B-Instruct achieved a peak score of 79.83 on BFCLv2, representing a top-tier result for open-source models.

Limitations and Future Work

Despite the improvements, several challenges remain. The current training data (ToolACE) lacks highly complex, nested function-call scenarios, leading some fine-tuned models to struggle with the most intricate Nexus tasks. Additionally, the current framework is limited to single-turn interactions.

Future research will focus on expanding the dataset to include multi-turn conversations and nested calls. The authors also plan to investigate adaptive templates that can dynamically adjust the depth of reasoning based on the complexity of the user's request, optimizing for both speed and accuracy.

Conclusion

By replacing unstructured reasoning with guided, template-based curricula, this work demonstrates that LLMs can achieve higher reliability and transparency in function calling. The combination of structured prompting for large models and targeted fine-tuning for smaller models provides a robust pathway toward more capable and interpretable AI agents.

Summary updated

BibTeX
@misc{dang2025improving,
  author = {Hong Dang and Tianyi Liu and Zhuofeng Wu and Jingfeng Yang and Haoming Jiang and Jun Yang and Pei Chen and Zhengyang Wang and Helen Wang and Huasheng Li and Bing Yin and Meng Jiang},
  title = {{Improving Large Language Models Function Calling and Interpretability via Guided-Structured Templates}},
  year = {2025},
  doi = {10.18653/v1/2025.emnlp-main.1242},
}
Figure