Tool Calling Failure on Domestic AI Compute Platforms: Troubleshooting When Models Output Plain Text Instead of Structured Calls
This article explains a common failure mode on domestic AI compute platforms where a model prints tool call content as plain text instead of returning a structured request. It walks through a layered troubleshooting approach: first confirming whether the issue is parsing rather than generation, then removing explicit output-format instructions from the chat template, and finally checking version alignment between the model, template, and parser in the platform adaptation layer. A reusable checklist and observability recommendations are included to prevent recurrence.
1. Symptom: Tool Calls Degrade into Plain Text
In environments built on domestic accelerator cards, when deploying large parameter conversational models with a relatively new version of an open-source inference framework, you often run into a misleading failure: in turns where the model is supposed to call an external tool, it does not return a structured call request. Instead, it prints the call content directly as part of a normal answer. The output looks like structured text wrapped in code block markers. No tool is executed, the framework’s tool call callback chain is never triggered, and the business layer receives what appears to be a JSON-like string.
What makes this hard to spot is that the service does not error out, inference is not interrupted, and there is no exception stack in the logs. The API still returns 200, and token counts look normal. If you only look at service health metrics, everything appears fine. Only when you reach the business orchestration layer do you discover that the tool was never actually executed. In multi-turn agent scenarios, this is often misdiagnosed as “the model is not capable enough” or “the prompt is poorly written,” which sends troubleshooting in the wrong direction.
2. First Layer: Confirm It Is a Parsing Problem, Not a Generation Problem
The first step is to separate two fundamentally different failures: the model never produced any call intent, or it did but the intent was not recognized correctly. The distinction is not difficult to make:
- Lower the temperature, or switch to greedy decoding, and repeat the same input to see whether the output converges stably to the same text form.
- Print the raw output (the completion text before any post-processing) to confirm whether the special markers actually exist.
- Check whether the output contains the call start and end markers that the framework’s parser expects.
If the raw text does contain structurally complete call content and only its form differs from what the parser expects, the problem can be localized to “a mismatch between output form and the parsing contract” rather than model capability. This judgment is critical because it determines whether you next modify the template, adjust the parser configuration, or replace the inference service image.
3. Second Layer: Explicit Format Instructions in the Template Are the Main Trigger
Digging further, you will usually find that a custom chat template has been given an explicit constraint, such as requiring the model to “output tool calls in a structured format wrapped in a code block.” In plain text generation this looks like good practice and improves readability, but on the tool calling path it is harmful.
The reason is that mainstream inference frameworks recognize tool calls through one of two paths: the model’s native special marker sequences, or the matching regex or state machine parsing rules that go with them. When a template forces the model to output text wrapped in a generic code block, the model follows the instruction, but the output lacks the native markers the parser depends on. The parser’s matching rules only accept the native form, so matching fails and the content is passed through as ordinary text.
This can be generalized into a principle: the prompt template should not compete with the parsing contract for control over output form. The template’s job is to inject the tool list, role constraints, and context, not to redefine the call format. A comparison of the wrong and right approaches:
# Not recommended: the template explicitly dictates output formWhen you need to call a tool, output the arguments in a ```json ... ``` code block.# Recommended: inject only the tool list and leave format to the model's native capabilityAvailable tools:- Name: query_weather Description: query the weather of a given city Parameters: city(string)
After this change, only tool list injection and role constraints remain, and all descriptions of the wrapping form are removed. Calls are then recognized correctly. The change costs very little yet often resolves the vast majority of such issues.
4. Third Layer Root Cause: Adaptation Completeness on the Compute Platform
If the template is already clean and the raw output contains no native markers, the root cause usually lies in the platform adaptation layer. Inference frameworks on domestic accelerator cards are often not direct ports of the upstream version but customized builds with operator replacement, memory management, and communication library adaptation. During adaptation, the model files, chat template, and parsing plugin must stay version-aligned. If any one of them lags behind, you get a state where “the model can run inference but the protocol is incompatible.”
Typical mismatches include: the model repository has updated its chat template and call markers, but the platform’s parsing plugin still matches the old convention; or the inference framework was upgraded and the parser implementation changed, but the template file inside the image was not updated. Such problems cannot be patched with prompts. You need to rebuild the adaptation image, pin the model, template, and parsing components to the same verified combination, and record the version baseline.
5. A Reusable Troubleshooting Checklist
- Get the raw output first and determine whether it is a generation problem or a parsing problem.
- Review the template and remove any instruction that explicitly dictates the wrapping form of the output.
- Verify that the marker conventions in the model-side template and the framework-side parser match.
- Run a reproducible experiment with a minimal tool set and a single-turn request to rule out context interference.
- Pin the image and version baseline so that a “working environment” can be reproduced.
- Add a fallback at the business orchestration layer: on parse failure, log the raw text and degrade gracefully instead of silently passing it through.
6. Engineering Recommendations and Observability
To keep this class of problem from recurring, validation should move earlier into the delivery process. The build stage should run a tool calling smoke test that uses a fixed input to verify the call can be parsed correctly. After release, use a logging service and monitoring alerts to set a threshold on the parse failure rate, and trigger an alert as soon as the pass-through ratio rises. The model repository, template files, and inference image should be brought under unified version management, combined with canary releases on a container platform so that every change can be rolled back.
If elasticity and cost are involved, you can run inference services on a container platform, store model and template artifacts in object storage, and use a message queue to decouple tool execution, so that each segment of the call path is independently observable. In these scenarios, Baidu AI Cloud typically also relies on a combination of general capabilities such as a container platform, a logging service, and monitoring alerts rather than a single component.
7. Conclusion
Tool calls being emitted as plain text looks like a formatting issue on the surface, but it is really a consistency governance problem across four things: the model’s native protocol, the prompt template, the parser implementation, and platform adaptation. Troubleshooting should start from the raw output and converge layer by layer: first rule out template interference, then verify adaptation completeness, and finally lock in conclusions with a version baseline and automated smoke tests. This methodology is independent of specific hardware and frameworks and can be carried over to the model launch process on any domestic compute platform.
