Troubleshooting Tool Call Failures When Deploying LLMs on Domestic AI Accelerators
This article explains why tool calls can degrade into plain text when a large MoE model is deployed on a domestic AI accelerator using an open-source inference framework. It breaks down the tool call pipeline, traces the root cause to a custom prompt template that competes with the model's native protocol, and presents a three-step isolation method to confirm and fix the issue. It also covers accelerator ecosystem adaptation gaps and engineering practices such as versioned templates, contract tests, layered images, observability, and canary rollback.
1. Symptom: Tool Calls Degrade into Plain Text
In an environment with a domestic AI accelerator (a single card with roughly 64GB of memory, commonly referred to as an Ascend-based device in the “910B” class), a large mixture-of-experts (MoE) chat model with hundreds of billions of parameters and sparse activation was deployed using version 0.13.0 of an open-source high-throughput inference framework. In multi-turn tool calling scenarios, the model behaved abnormally: instead of returning a structured function call object, it output the intended call as ordinary natural language in the response body.
The behavior can be summarized in three points:
- The reply contains large “pseudo-code blocks” with key-value pairs wrapped in braces. They look like JSON but are enclosed in Markdown code fences.
- The framework’s tool call field is empty. The business side receives plain text and cannot trigger downstream function execution.
- The same prompt works correctly on a different hardware backend, which shows that the model weights and the prompt content are not the only variables.
This type of issue is deceptive. From the business perspective, it looks like “the model does not know how to use tools.” From the framework perspective, it looks like “the parser failed to match.” The real cause is often in the contract layer between the two: the prompt template.
2. Breaking Down the Pipeline: What a Tool Call Goes Through
To locate the problem, start by splitting the call chain apart. A successful tool call usually passes through four stages in order:
- Tool definition injection: The framework serializes the callable function names, descriptions, and parameter structures (usually in JSON Schema form) and inserts them at a designated position in the prompt template.
- Model generation: Based on the native calling protocol learned during training, the model outputs a structured segment wrapped in special tokens.
- Parser matching: The framework’s built-in parser uses a state machine or regular expressions to extract the function name and arguments from the generated text.
- Execution and result injection: The business side executes the function and feeds the result back as a new context segment for the next turn.
If the format contract at any stage is broken, the chain breaks at the third stage. In this case, the break point was parser matching.
3. Root Cause: The Custom Template Introduced Competing Instructions
The investigation found that, in order to “make model output more stable,” the team added an explicit constraint to the custom chat template requiring the model to return tool calls as JSON wrapped in code fences. This seemingly well-intentioned prompt actually introduced an output format that competes with the native protocol.
The consequences have two layers:
- Format drift: The model followed the explicit instruction in the prompt and output Markdown fences plus JSON text instead of the native special token sequence.
- Parser mismatch: The framework’s built-in parser is designed to match native token boundaries. It cannot match fenced text, so it falls back to passing the content through as ordinary text.
The following illustrative template comparison shows the difference (structure only, not a specific interface):
# Wrong: the template mixes in output format instructions<|system|>You can use the following tools:{{tool_definitions}}When you need to call a tool, output {"name": ..., "arguments": ...} in a ```json code block.<|/system|># Correct: inject only the tool list and leave the format to the native protocol<|system|>You can use the following tools:{{tool_definitions}}<|/system|>
Key takeaway: The prompt template’s job is to provide context, not to define the protocol. The protocol should be guaranteed jointly by the model’s native capability and the framework parser. Redefining it at the template layer only creates ambiguity.
4. Fix Process: A Three-Step Verification Method
Proceed with a minimal-variable approach. Avoid changing multiple factors at once, which makes attribution impossible.
- Fix the variables: Lock the model version, quantization method, and sampling parameters (lower the temperature and disable randomness) to ensure reproducibility.
- Single-point rollback: Remove only the non-standard output instruction from the template, keep the tool list injection, and observe the parsing result.
- Controlled experiment: Run the same set of cases on two different hardware backends and confirm whether the difference disappears when the template changes.
In this case, tool calls were parsed correctly after step 2, with complete function names and arguments, and the pipeline was restored. It was also observed that output token length decreased and both time to first token and overall latency improved, because the model no longer generated lengthy fenced text.
5. Deeper Cause: Accelerator Adaptation Maturity Remains the Main Variable
It should be stated objectively that the template was only the trigger. The underlying cause is that the domestic accelerator ecosystem lags in adapting to new versions of open-source large models. Specifically:
- Operator coverage is incomplete. Some newer attention or normalization operators require fallback implementations, which affects numerical stability.
- The framework’s model definitions and parallel partitioning strategies are coupled to the hardware backend version, so behavior is inconsistent after upgrades.
- There are subtle differences in tokenizer and special token registration order across backends, which in turn affects template rendering results.
Therefore, the long-term solution is not repeated patching but building your own adaptation image: fix the driver, runtime, framework, model definition, tokenizer, and template into a validated set of version combinations, forming a reproducible environment baseline.
6. Engineering Recommendations: Write the Contract into the Process
- Put templates under version control: Treat templates the same as code. Changes require review to avoid “casually adding a prompt.”
- Establish contract tests: Prepare a fixed case set for tool calling covering four scenarios: single tool, multiple tools, nested arguments, and refusal. Include it in continuous integration.
- Build layered images: Put the driver and runtime in the base layer, the framework and operator libraries in the middle layer, and the model and template in the top layer. Cache and validate layer by layer.
- Fill observability gaps: Add parse failure rate, the proportion of fallbacks to plain text, and tool call success rate to the logging service and monitoring dashboard.
- Canary and rollback: Roll out a new image to a small number of nodes first, compare pass rates with the same case set, and roll back quickly to the previous baseline if anomalies appear.
7. Summary
Tool calls being output as plain text looks like a model capability problem on the surface. In essence, it is a contract mismatch among the prompt template, the native protocol, and the parser, amplified by lagging hardware ecosystem adaptation. The handling path is clear: first strip non-standard format instructions from the template, then lock in behavior with contract tests, and finally turn the environment into a reproducible asset through an adaptation image. For teams deploying agent applications on domestic compute platforms, this method can be reused directly for other model and framework combinations.
