Skip to content

fix: improve XML tool call error recovery with comprehensive guidance#11480

Draft
roomote[bot] wants to merge 1 commit intomainfrom
fix/improve-xml-tool-call-error-recovery
Draft

fix: improve XML tool call error recovery with comprehensive guidance#11480
roomote[bot] wants to merge 1 commit intomainfrom
fix/improve-xml-tool-call-error-recovery

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Feb 15, 2026

Related GitHub Issue

Closes: #11106

Description

This PR attempts to address Issue #11106 where models (Grok, Gemini, and others) intermittently produce XML-style tool markup instead of using native tool calling, causing a blocking error loop.

Root cause: When the model emits XML tool tags in its text response, the error message pushed to the conversation history was too brief for the model to self-correct. The model would repeat the same mistake, hit the consecutive mistake limit, and stall the task.

Changes:

  • src/core/prompts/responses.ts: Added formatResponse.xmlToolCallError() that returns a comprehensive error message including:

    • Clear explanation of what went wrong (XML markup detected)
    • Explicit instruction not to embed tool invocations as XML tags
    • The standard tool-use instructions reminder (same pattern as noToolsUsed())
    • Next-step guidance to help the model recover
  • src/core/assistant-message/presentAssistantMessage.ts: Updated the missing tool_use.id error path to use the new comprehensive error message in userMessageContent (what the model sees), while keeping the user-facing error concise

  • src/core/tools/BaseTool.ts: Improved error messages for XML detection in params and missing nativeArgs

  • src/core/prompts/__tests__/responses-xml-tool-call-error.spec.ts: Added dedicated test suite for the new xmlToolCallError() function

Test Procedure

  • Ran all related test suites (27 tests across 4 files, all passing)
  • Ran full monorepo lint and type-check (all 14 packages pass)
  • Existing tests in presentAssistantMessage-unknown-tool.spec.ts and presentAssistantMessage-images.spec.ts continue to pass unchanged

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue
  • Scope: Changes are focused on the linked issue
  • Self-Review: Performed a thorough self-review
  • Testing: Added new test suite for xmlToolCallError(), existing tests pass
  • Documentation Impact: No documentation updates required
  • Contribution Guidelines: Read and agree

Documentation Updates

No documentation updates are required.

Additional Notes

Feedback and guidance are welcome. The key insight is that when the model makes XML tool call mistakes, we now provide it with the same quality of guidance (tool instructions reminder + next steps) that we give for other error types like noToolsUsed() and missingToolParameterError(). This makes it much more likely the model can self-correct on the next turn rather than entering a stall loop.

…#11106)

When models produce XML-style tool markup instead of using native tool
calling, the error message now includes explicit tool-use instructions
and next-step guidance (similar to noToolsUsed), making it much more
likely the model can self-correct on the next turn.

Changes:
- Add formatResponse.xmlToolCallError() with tool instructions reminder
- Use comprehensive error in presentAssistantMessage userMessageContent
- Improve error messages in BaseTool for missing nativeArgs
- Add dedicated test suite for xmlToolCallError()
@roomote
Copy link
Contributor Author

roomote bot commented Feb 15, 2026

Rooviewer Clock   See task

Reviewed all changed files. No bugs or issues found.

The changes are clean, well-scoped, and follow existing patterns (mirrors noToolsUsed() structure). The separation between user-facing error messages and model-facing comprehensive guidance is well-implemented. All existing tests pass alongside the 6 new tests.

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] XML tool calls are no longer supported. Remove any XML tool markup

1 participant