claude-code - 💡(How to fix) Fix [Bug] Tool-call parser rejects indented XML tags with vague "malformed" error

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Title: Tool-call parser rejects leading whitespace on <invoke>/<parameter> tags with a vague "malformed" error The same call parses correctly when the tags start at the beginning of the line. The error message does not indicate the cause (leading whitespace), so it is easy to repeat the 2. Observe the "malformed and could not be parsed" error.

  • (b) If strict parsing is intended, make the "malformed" error specific about the cause (e.g. "tool-call tags must start at the beginning of the line; leading whitespace

Code Example

[]
RAW_BUFFERClick to expand / collapse

Bug Description

Title: Tool-call parser rejects leading whitespace on <invoke>/<parameter> tags with a vague "malformed" error

Description:

When a tool call is emitted with the <function_calls> / <invoke> / <parameter> tags indented (i.e. with leading whitespace) instead of starting at column 0, the call fails to parse and returns:

Your tool call was malformed and could not be parsed. Please retry.

The same call parses correctly when the tags start at the beginning of the line. The error message does not indicate the cause (leading whitespace), so it is easy to repeat the same mistake several times in a row before identifying it.

Steps to reproduce:

  1. Emit a tool call where the <invoke> and <parameter> tags are indented, e.g.: <invoke name="Bash"> <parameter name="command">echo hi</parameter> </invoke>
  2. Observe the "malformed and could not be parsed" error.
  3. Re-emit the identical call with the tags at column 0 — it now parses and runs.

Requests:

  • (a) Make the parser tolerant of leading whitespace — trim/ignore indentation before the tool-call tags so indented blocks parse correctly.
  • (b) If strict parsing is intended, make the "malformed" error specific about the cause (e.g. "tool-call tags must start at the beginning of the line; leading whitespace found"), so the model can self-correct immediately instead of retrying blindly.

Impact: Causes repeated failed tool calls and wasted turns. Note: failed calls are rejected at parse time and are not executed, so there is no risk of partial/corrupted execution — but it interrupts progress.


Environment Info

  • Platform: linux
  • Terminal: wsl-Ubuntu-24.04-D
  • Version: 2.1.158
  • Feedback ID: 344f8a69-ea19-4057-a384-269425f487b9

Errors

[]

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [Bug] Tool-call parser rejects indented XML tags with vague "malformed" error