Sanitize Tool Arguments
GitAuto strips malformed XML fragments from the model's tool arguments before parsing them as JSON. The model sometimes includes XML artifacts from its own internal processing in tool call arguments, which causes JSON parsing failures that crash the agent loop.
Why This Exists
The model's tool calls are structured as JSON, but the model occasionally leaks fragments of its own XML-based thinking process into the arguments. The most common artifact is a trailing </antml fragment that appears at the end of argument strings. When the agent loop tries to parse these arguments as JSON, the parser throws an error and the entire iteration fails. This was an intermittent but persistent issue that was difficult to debug because the XML fragment appeared random.
Why Models Leak XML Into JSON
The model's API uses XML-like structures internally for tool call formatting. When generating JSON tool arguments, the model occasionally appends fragments of these internal formatting tokens at the end of its output. This is a known edge case in autoregressive generation: the model generates tokens one at a time, and near the end of a structured output, it can "drift" into a different format it associates with output boundaries. The result is a JSON string with a stray XML fragment appended, which breaks JSON parsing.
How It Works
Before parsing tool arguments, GitAuto runs a sanitization pass that detects and removes known XML artifact patterns. The sanitizer strips trailing XML-like fragments that do not belong in JSON, then validates that the remaining content is valid JSON. This runs on every tool call and adds negligible overhead since it is a simple string operation.
Related Features
- Tool Name Correction - Fixes hallucinated tool names alongside sanitized arguments
- Tool Argument Correction - Routes arguments to the correct tool after sanitization
Need Help?
Have questions or suggestions? We're here to help you get the most out of GitAuto.
Contact us with your questions or feedback!