Tool Calling Failures on Domestic AI Accelerator Platforms: A Troubleshooting Guide

    This article walks through a structured troubleshooting process for a common failure on domestic (China-made) AI accelerator cards: tool calls that degrade into plain text instead of structured requests. It explains how to separate generation failures from parsing failures, how custom chat templates can override a model's native output protocol, and how incomplete adaptation across the inference framework, model template, and parser leads to silent capability degradation. A reusable diagnosis sequence and a pre-launch acceptance checklist are included.

    1. Symptom: Tool Calls Degrade into Plain Text

    After deploying a large open-source model for inference on a domestic accelerator card, a typical anomaly appears: multi-turn conversation and knowledge Q&A work normally, but as soon as a scenario requires external tool coordination, the model does not emit a structured call request. Instead, it returns plain text wrapped in a code block. The business layer receives this text, cannot trigger any function execution, and the chain breaks immediately.

    What makes this issue confusing is that nothing reports an error. The API returns a normal status, the token stream is continuous, and monitoring metrics all look steady. The actual fault lies neither in the inference operators nor in memory or communication, but between two easily overlooked stages: input construction and output parsing.

    2. First Layer: Confirm It Is a Parsing Failure, Not a Generation Failure

    The first step is to distinguish two entirely different failure types:

    • Generation failure: the model never produces any call intent and outputs a natural-language reply.
    • Parsing failure: the model does produce call intent, but the server fails to recognize it as a structured object.

    The check is straightforward: print the raw output (the complete text before any post-processing) and inspect it. If it already contains the function name, parameter keys and values, and only has an extra non-standard wrapping layer, the problem can almost certainly be narrowed down to parsing.

    In this case, the raw output did contain the complete call elements, which shows that intent generation was fine and that the mismatch was between the format convention and the parsing rules.

    3. Second Layer: Overreaching Instructions in the Chat Template

    Tracing further upstream to the input side reveals that a custom chat template had an explicit constraint added manually, instructing the model to “output tool calls in a certain code block form.” The intent behind this was reasonable — constraining the output structure in natural language makes it easier for humans to read. But it conflicts with the model’s native behavior.

    A large model’s tool calling ability typically relies on special marker sequences fixed during training: once the model recognizes the available tool list, it spontaneously wraps the call request in those markers, and the server-side parser is designed to match them. When a template forcibly rewrites the output shape using natural language, the model obediently follows the latter and produces text the parser cannot recognize.

    This can be generalized into a principle: a template should only inject context and the tool list; it should not overreach by defining the output protocol. Ownership of the output protocol belongs to the contract between the model and the parser, and any unilateral change by either side breaks that contract.

    A schematic comparison of the wrong and right approaches (pseudocode, showing structural differences only):

    1. # Not recommended: template carries output format constraints
    2. [SYSTEM] You can use the following tools: {tool_list}
    3. [SYSTEM] When calling a tool, output the parameters in a ```json code block.
    4. # Recommended: inject only the tool list, leave the output format to the model's native capability
    5. [SYSTEM] Available tools: {tool_list}
    6. [USER] {question}

    4. Third Layer, Root Cause: Incomplete Adaptation on Heterogeneous Compute Platforms

    After removing the non-standard output instruction from the template, the call was parsed correctly and the symptom disappeared. But stopping here only bypasses the trigger; the root cause remains. There is a gap in how the heterogeneous accelerator card version is adapted to the open-source model, specifically: the inference framework version, the model’s native template, and the parser implementation were never aligned and validated within the same image.

    Adaptation gaps usually appear in three places:

    1. The model-side template file is missing or replaced, so the special markers are not injected correctly.
    2. The parser version does not match the model version, and the matching rules lag behind the model’s behavior.
    3. The combination of dependency library and operator library versions was never validated as a whole, so individual capability paths degrade silently.

    The correct approach is therefore to rebuild a fully validated adaptation image that fixes the framework, template, parser, and dependencies as one unit, rather than applying temporary patches on the business side.

    5. A Reusable Diagnosis Flow

    Proceed in the following order to avoid blind parameter tuning:

    • Print the raw output before any post-processing to determine whether it is a generation or a parsing problem.
    • Check the template content to confirm whether it carries format-constraint instructions.
    • Verify that the model’s built-in chat template and tool injection method are fully preserved.
    • Reproduce with a minimal input set: single turn, single tool, no parameters, then increase complexity step by step.
    • Validate the correspondence between the parser version and the model version.
    • Fix the above configuration at the container image level to form a rollback-capable version.

    6. Pre-Launch Acceptance Checklist

    • All four cases pass: single tool with no parameters, single tool with parameters, selection among multiple tools, and refusal when a tool is unavailable.
    • Parsing results are identical under both streaming and full-response modes.
    • In multi-turn conversations, tool context does not bleed across turns or get lost.
    • Abnormal inputs (missing parameters, wrong types) are reliably intercepted by the parser and return readable errors.
    • Image, template, and parser version numbers are each recorded for traceability.

    7. Practical Takeaways

    Deploying models on heterogeneous compute environments is often less about raw compute and more about contract consistency. Treat the template, parser, and image as one unit to govern, use the raw output as first-hand evidence, and use minimal reproduction to narrow the variable range. Most behavior anomalies that look inexplicable can then be located reliably. If further isolation and canary rollout are needed in large-scale inference scenarios, general capabilities such as container platforms, log services, and monitoring alerts can help make configuration versions traceable and anomalies observable.