When building AI coding assistants, the choice between JSON and XML tool calls can dramatically impact your model’s performance. Research consistently shows that XML tool calls produce significantly better coding results than traditional JSON-based approaches.
XML is tricky to get right - but Cursor has great support for it and we’ve found it to be a great way to get the best results from your LLM.
Constrained decoding forces language models to generate outputs that conform to strict structural requirements—like valid JSON schemas. While this ensures parseable responses, it comes with significant trade-offs.When you require an LLM to output valid JSON for tool calls, the model must:
Maintain perfect syntax throughout generation
Balance content quality with structural constraints
Allocate cognitive resources to format compliance rather than reasoning
Cognitive Overhead: Models spend computational “attention” ensuring JSON validity instead of focusing on code logic and correctness.Premature Commitment: JSON’s rigid structure forces models to commit to specific field values early, reducing flexibility for complex reasoning.Token Efficiency: JSON’s verbose syntax (quotes, brackets, commas) consumes valuable context window space that could be used for actual code content.Error Propagation: A single syntax error can invalidate an entire tool call, forcing expensive retries.
Cognitive Freedom: Models can focus entirely on code quality without syntax constraints.Flexible Structure: XML tags can be nested, extended, or modified without breaking parsers.Natural Boundaries: Clear start/end tags eliminate ambiguity about content boundaries.Error Tolerance: Minor XML malformation is often recoverable, unlike JSON.Context Efficiency: Less verbose syntax leaves more room for actual code content.
You are an expert coding assistant. When making code changes, use XML tool calls in this format:<tool_name><parameter_name>parameter_value</parameter_name><code>actual code content here</code></tool_name>Focus on code quality and correctness. Don't worry about XML formatting - just ensure the content within tags is accurate and helpful.
<edit_file><target_file>path/to/file.ts</target_file><instructions>Human-readable explanation</instructions><code_changes><!-- Actual code here --></code_changes></edit_file>
XML tool calls represent a paradigm shift from constrained generation to natural language reasoning. By removing JSON’s structural overhead, models can focus entirely on producing high-quality code.For production coding assistants, XML tool calls aren’t just an optimization—they’re essential for achieving state-of-the-art performance.Ready to implement XML tool calls? Start by updating your system prompts and parsers, then measure the improvement in your coding assistant’s output quality.