Hadal Research
PAPER
15 November 2026
7 min

← Notes

Framing newlines: how tool-call parsers rewrite the files agents write

Kyssta

tool use · evaluation · format design · agents

Paper (PDF, 4 pages)Code and raw results

A model that can drive a file editor still cannot reliably write a file, because the format it writes through — and the parser on the other side — decide whether the last byte survives. This is a measurement of that gap, on real files, with no model in the loop.

Qwen, LFM3, Granite 4.2 and MiniMax all emit tool calls as XML in which each argument value sits between a framing newline on either side of its tag. It is a clean design: one newline per side, no escaping, values may span lines. It is also, as it turns out, the exact place where agents silently lose data.

The contrast

<tool_call>
<function=write_file>
<parameter=content>
VALUE
</parameter>
</function>
</tool_call>

one newline each side is framing — nothing else is

Remove exactly those two newlines and the format is invertible: we rendered 1,762 real files (Python sources, markdown, system configs, shell scripts) as write_file calls and 1,759 came back byte-identical. The information is all there.

What was measured

  • Corpus. 1,762 files, 26 MB, from a working developer machine. 99.1% of them end with a newline.
  • Parsers. Five implementations: strict frame, the frame-plus-spaces fix a production agent SDK shipped this month, line-split, .strip(), and .rstrip('\n').
  • Grading. Exact string equality. No model, no GPU, no network — the whole experiment reruns in under a minute.

Results

parserpreservedcorruptedfailure mode
strict frame99.8%3only files containing the terminator
frame + spaces/tabs (shipped fix)99.1%15single-line values still stripped
line-split + right-trim98.9%19trailing blank lines collapse
.strip()0.9%1,747final newline removed from every multiline file
.rstrip('\n')0.0%1,762removes frame and value newlines; adds a leading one
Table 1. Payload fidelity of five parser implementations over 222 real files.

On a task shaped like “write this file”, graded by exact content, the same perfect agent scores 99.8% under a strict parser and 0.9% under .strip(). A 99-point swing with no model involved — the benchmark would be measuring the parser and reporting it as model capability.

The second failure class

The format defines no escaping for its own terminator. A payload containing </parameter> truncates at that point, and the remainder is parsed as additional parameters — so a file being written can change the call's path. Three files in our working tree contain the terminator; rendered through the format they returned at 3.0%, 11.3% and 5.2% of their original length.

This is not hypothetical

Two production systems reported exactly this, one week apart. OpenHands software-agent-sdk, PR #6451: “the parser then called .strip() on every <parameter=…> value … so a file_editor create wrote file_text without the first line's indentation or the final newline.” Their fix is the 97.3% row above. MTPLX issue #691: “a write whose content ends in \n arrives at the client without it”, and the next turn re-tokenises differently and drops out of the session bank — a prefix-cache miss caused by a parser.

Neither quantifies reach, and we are not aware of a prior measurement of it. Both treat it as a bug in one adapter rather than a property of a format family used by most open agent models.

Where in the stack it happens

The reference server gets it right, explicitly. vLLM parses this same Qwen3 format with a helper called _trim_wrapping_newlines, whose docstring reads “strip one leading and one trailing newline (the Qwen3 template markup)”. That is the 100% row above. SGLang's Granite detector reaches the same result by scanning tags rather than trimming values.

The loss therefore has an address: clients that re-derive the parse from template text. A server ships with the model's chat template and knows which newline is markup. An agent framework receives arguments as text and has to guess — and when it guesses with.strip(), it eats the payload. That asymmetry is also why the bug survives review: the server-side tests pass, because the server is correct.

Why benchmarks miss it

Tool-use benchmarks grade function names and short arguments — identifiers, numbers, enums — which whitespace trimming cannot hurt. The failure appears only when the argument is a document, which is what coding agents do all day. It also hides in benchmark design: our own tool-use suite generated write payloads without trailing newlines, deliberately, because teaching a trailing newline the format “could not express” seemed unfair. That instinct — avoid the case that breaks the harness — is how a systematic problem stays invisible.

Recommendation

  • Parse by frame, not by whitespace: remove exactly one leading and one trailing newline.
  • Escape or reject the terminator on emit; the format currently permits it and cannot represent it.
  • Prefer JSON arguments where the transport allows; JSON's escaping is why this class does not exist there.
  • Grade payload fidelity explicitly. A tool-use benchmark that never asks for a trailing newline cannot see any of this.

Limitations: 1,762 files from one machine, dominated by a Python standard library. We measure the format and the parsers, not the models; whether a given model emits the framing correctly is a separate question that needs GPU inference. Parser variants are reimplementations of documented behaviour, released with the results so the mapping can be checked line by line.

Sources
Status

Unpublished manuscript. Not peer reviewed; no priority claim is made.