Batch API: tool_use input wrapped in $PARAMETER_NAME placeholder key (claude-opus-4-7)
Summary
When using the Messages Batch API with forced tool_use (tool_choice={"type":"tool","name":"..."}) on claude-opus-4-7, the returned tool input is frequently wrapped in a single key $PARAMETER_NAME instead of containing the schema's actual property names at the top level. The same prompt and schema, sent via client.messages.create (sync), returns the correct top-level keys 100% of the time.
Environment
- SDK:
anthropic(Python), latest stable - Model:
claude-opus-4-7 - Endpoint:
client.messages.batches.create/.retrieve/.results - Tool config:
tool_choice={"type":"tool","name":"save_topic_synthesis"}(forced)
Expected vs Observed
Expected:
tool_use.input == {
"tldr": "...",
"mechanism_summary": "...",
"evidence_strength": "emerging",
...
}
Observed (most items):
tool_use.input == {
"$PARAMETER_NAME": {
"tldr": "...",
"mechanism_summary": "...",
...
}
}
The literal string $PARAMETER_NAME does not appear anywhere in our prompt, tool schema, or system message.
Distribution from a single batch (10 messages, all stop_reason=tool_use)
| Request | Top-level keys | Output tokens |
|---|---|---|
| 1 | $PARAMETER_NAME (full inner) |
4573 |
| 2 | $PARAMETER_NAME (full inner) |
5668 |
| 3 | $PARAMETER_NAME (full inner) |
5221 |
| 4 | $PARAMETER_NAME (full inner) |
5513 |
| 5 | $PARAMETER_NAME (full inner) |
4853 |
| 6 | mixed: $PARAMETER_NAME + top-level tldr/mechanism_summary |
5525 |
| 7 | topic (different wrap key, single-key dict) |
4929 |
| 8 | $PARAMETER_NAME (empty inner dict) |
49 |
| 9 | top-level (correct) | 5353 |
| 10 | top-level (correct) | 5915 |
8/10 had non-conforming top-level shape; 2/10 conformed. Pattern repeated in a second independent batch with different inputs (same 10 messages re-submitted on a different day after schema/prompt changes): again 1 item came back stuck ($PARAMETER_NAME: {}, ~50 output tokens, smallest input).
Possibly related: tool_use that stops early with empty wrapper
Item 8 above: stop_reason="tool_use" but only 49 output tokens emitted, and the $PARAMETER_NAME wrapper was an empty dict. Recurring across our two batches: the failing item is consistently the one with the smallest prompt input (~10K tokens vs. ~17K average). Both stop_reason and tool_use block presence suggest the model thinks it completed successfully.
Reproducer (sketch)
import anthropic
client = anthropic.Anthropic()
schema = {
"type": "object",
"properties": {
"tldr": {"type": "string", "description": "..."},
"mechanism_summary": {"type": "string"},
"evidence_strength": {"type": "string", "enum": ["consolidated","emerging","speculative"]},
# ...several more required string/array fields...
},
"required": ["tldr", "mechanism_summary", "evidence_strength", ...],
}
batch = client.messages.batches.create(requests=[
{
"custom_id": f"item-{i}",
"params": {
"model": "claude-opus-4-7",
"max_tokens": 8000,
"system": [{"type": "text", "text": "<system prompt>", "cache_control": {"type": "ephemeral"}}],
"tools": [{
"name": "save_topic_synthesis",
"description": "Save structured composition.",
"input_schema": schema,
}],
"tool_choice": {"type": "tool", "name": "save_topic_synthesis"},
"messages": [{"role": "user", "content": "<long prompt with ~15-20K tokens of structured input>"}],
},
}
for i in range(10)
])
# wait for batch.processing_status == "ended", then for line in client.messages.batches.results(batch.id):
# inspect line.result.message.content[0].input
# Expect: most items wrap content in {"$PARAMETER_NAME": {...}}
Impact
Without client-side defensive unwrapping, the majority of batch responses fail strict downstream validation (Pydantic, JSON Schema validators) because expected fields are nested one level too deep. Forces every batch consumer to add a workaround like:
if len(input) == 1:
sole = next(iter(input.values()))
if isinstance(sole, dict) and "<sentinel_field>" in sole:
input = sole
Compounded with the stuck-early issue, the practical failure rate on a fresh batch is ~10% even with that workaround.
Workaround in place on our side
Detect len(input)==1 and unwrap; on <sentinel>=None (stuck output), re-issue the same request as a synchronous messages.create and accept the result. This pattern is described and committed at our repo if useful as reference.
Ask
Could the SDK / Batch API surface either (a) normalize the response shape to match sync mode, or (b) document the wrap behavior so consumers know to expect it? Currently the SDK type hints suggest top-level fields per the declared schema, which is misleading.
Update (2026-05-29): retested on claude-opus-4-8 + minimal reproducer
Re-tested after the 4.8 release. The $PARAMETER_NAME single-key wrapper no longer reproduces on claude-opus-4-8 (0/10 on the original workload that previously showed 8/10). However, the root issue — tool-input serialization leaking into tool_use.input — persists in a new form, and a minimal reproducer narrows the trigger.
Trigger isolated: a nested array<object> sub-schema. A flattened schema (scalars / arrays-of-scalars only) was clean in 28/28 runs across both models and both transports. The nested schema breaks on both.
Failure mode by version:
opus-4-7: top-level wrapped in a single non-schema key —$PARAMETER_NAME,topic, orinput(the last not in the original report).opus-4-8: internal tool-call markup (<parameter name="...">/</parameter>) leaks into a string field value, absorbing the following sibling field — so arequiredfield silently disappears while the object still looks well-formed.
Corrections to the original report:
- Not batch-only. It also reproduces via
client.messages.create(sync), at a lower rate than batch. The original "sync 100% correct" was likely a small-sample / schema-specific effect. - Wrapper-key set on 4.7 includes
inputin addition to$PARAMETER_NAMEandtopic.
Environment: SDK anthropic 0.104.1, anthropic-version: 2023-06-01. Reproducer script and per-request IDs available on request.
Would an SDK-side normalization PR be appropriate here, or is this expected to be fixed server-side? Happy to work on either the normalization or the documentation angle depending on the preferred direction.
Thanks for offering to help! Before picking a direction I re-tested on the newly released claude-opus-4-8 and built a minimal self-contained reproducer. The picture is more nuanced than the original report — sharing in case it changes the fix direction.
TL;DR: the exact $PARAMETER_NAME single-key wrapper is gone on claude-opus-4-8, but the underlying bug (tool-input serialization leaking into the output) isn't fixed — it changed shape. On 4.8 the internal tool-call markup (<parameter name="...">) leaks into string field values, swallowing sibling fields (including required ones). It's lower-rate but more insidious, since the result looks structurally valid and passes shallow checks.
The trigger is isolable: a nested array<object> sub-schema. A flat schema (only scalars / arrays-of-scalars) never reproduced it — 28/28 clean across both models and both transports.
Minimal repro: forced tool_choice, ~18K-token input, two schemas (one with effects: array<{effect, magnitude, ref_ids}>, one flattened), same SDK 0.104.1, anthropic-version: 2023-06-01, same day:
| model | schema | transport | conforming | broken |
|---|---|---|---|---|
| opus-4-7 | flat | batch | 8/8 | — |
| opus-4-7 | nested | batch | 2/8 | 6 × key-wrap ($PARAMETER_NAME/input/topic) |
| opus-4-7 | nested | sync | 3/4 | 1 × key-wrap |
| opus-4-8 | flat | batch+sync | 12/12 | — |
| opus-4-8 | nested | batch | 6/8 | 2 × XML-markup contamination |
| opus-4-8 | nested | sync | 3/4 | 1 × XML-markup contamination |
Two refinements to the original report: (1) it's not batch-only — it reproduces in messages.create too, just at a much lower rate than batch; (2) on 4.7 I also saw input as a wrapper key, not just $PARAMETER_NAME/topic. (Sync cells are n=4, so treat those rates as indicative, not precise.)
Re: SDK-side normalization vs server-side — I think the 4.8 variant argues for server-side. The 4.7 single-key wrap was cleanly unwrappable client-side, but the 4.8 contamination injects <parameter name="..."> inside a string value and drops the swallowed field entirely — there's nothing for the SDK to losslessly recover. A defensive SDK check could detect it (reject/retry on a <parameter name= substring or a missing required field) but not repair it. So: server-side fix for the leak; documentation still worthwhile in the meantime. Happy to share the full reproducer script + request-ids if useful.
Minimal self-contained reproducer (no external deps beyond the SDK), in case it's useful for triage. Forced tool_choice, ~15K-token input, two schemas (nested array<object> vs flattened). Run submit_batch then report_batch <id>, or sync.
repro_minimal.py (~180 lines)
"""Minimal, self-contained reproducer for anthropic-sdk-python#1607.
Tool-input serialization leaks into `tool_use.input` under forced
`tool_choice`, triggered by a nested `array<object>` sub-schema + large
input. A flattened schema (scalars / arrays-of-scalars) never reproduces it.
Failure mode differs by model:
- claude-opus-4-7: top-level wrapped in a single non-schema key
($PARAMETER_NAME / input / topic).
- claude-opus-4-8: internal tool-call markup (<parameter name="...">)
leaks INTO a string field value, swallowing the following sibling
(a required field disappears while the object still looks well-formed).
Reproduces in BOTH messages.batches (high rate) and messages.create
(lower rate). SDK 0.104.1, anthropic-version 2023-06-01.
Usage:
export ANTHROPIC_API_KEY=...
python3 repro_minimal_public.py submit_batch
python3 repro_minimal_public.py report_batch <batch_id>
python3 repro_minimal_public.py sync
"""
import json
import os
import sys
from collections import Counter
import anthropic
MODELS = ["claude-opus-4-7", "claude-opus-4-8"]
N_PER_CELL = 8
N_SYNC = 4
MAX_TOKENS = 6000
TOOL_NAME = "save_report"
# --- The suspected trigger: a nested array<object> sub-schema ---
NESTED_SCHEMA = {
"type": "object",
"properties": {
"summary": {"type": "string", "description": "2-3 sentence summary."},
"strength": {"type": "string", "enum": ["strong", "moderate", "weak"]},
"observations": {
"type": "array",
"items": {
"type": "object",
"properties": {
"observation": {"type": "string"},
"magnitude": {"type": ["string", "null"]},
"source_ids": {"type": "array", "items": {"type": "integer"}},
},
"required": ["observation"],
},
},
"open_questions": {"type": "array", "items": {"type": "string"}},
},
"required": ["summary", "strength", "observations", "open_questions"],
}
# --- Control: same information, NO nested array<object> ---
FLAT_SCHEMA = {
"type": "object",
"properties": {
"summary": {"type": "string", "description": "2-3 sentence summary."},
"strength": {"type": "string", "enum": ["strong", "moderate", "weak"]},
"main_observation": {"type": "string"},
"magnitude": {"type": ["string", "null"]},
"source_ids": {"type": "array", "items": {"type": "integer"}},
"open_questions": {"type": "array", "items": {"type": "string"}},
},
"required": ["summary", "strength", "main_observation", "source_ids", "open_questions"],
}
SCHEMAS = {"nested": NESTED_SCHEMA, "flat": FLAT_SCHEMA}
# Neutral filler to reach ~18K tokens (the regime where the bug appears).
_PARA = (
"Report {i}: bench test of a mid-range smart thermostat firmware build under "
"sustained load. Observed reduced standby power draw, faster sensor polling, and "
"a regression in Wi-Fi reconnect time after router reboots. Telemetry captured: "
"setpoint drift, relay actuation latency, OTA update duration, and crash counts "
"across a 72-hour soak. The authors note effect size depends on ambient "
"temperature and the scheduling profile. Internal source_id={i}. "
)
def _big_input(seed: int) -> str:
parts = ["Synthesize the findings below by calling save_report exactly once.\n\n"]
for k in range(130):
parts.append(_PARA.format(i=(seed * 1000 + k)))
parts.append("\n\nCompose: summary, strength, the main observations (each with "
"observation, magnitude and source_ids), and open_questions.")
return "".join(parts)
SYSTEM = ("You are an evidence synthesizer. ALWAYS call save_report. "
"Populate every field per the declared schema.")
def _client():
return anthropic.Anthropic()
def _params(model, schema_key, seed):
return {
"model": model,
"max_tokens": MAX_TOKENS,
"system": [{"type": "text", "text": SYSTEM, "cache_control": {"type": "ephemeral"}}],
"tools": [{"name": TOOL_NAME, "description": "Save structured report. Call exactly once.",
"input_schema": SCHEMAS[schema_key]}],
"tool_choice": {"type": "tool", "name": TOOL_NAME},
"messages": [{"role": "user", "content": _big_input(seed)}],
}
def _classify(inp, schema_key):
blob = json.dumps(inp, ensure_ascii=False)
xml_leak = "<parameter name" in blob or "</parameter>" in blob or "$PARAMETER_NAME" in blob
base = {"xml_leak": xml_leak}
if not isinstance(inp, dict):
return {"shape": "non_dict", **base}
keys = list(inp.keys())
schema = SCHEMAS[schema_key]
real = set(schema["properties"].keys())
missing = sorted(set(schema.get("required", [])) - set(keys))
base.update(keys=keys, missing_required=missing)
if len(keys) == 1 and keys[0] not in real:
return {"shape": "wrapped", "wrap_key": keys[0], **base}
if xml_leak:
return {"shape": "contaminated", **base}
if schema_key == "nested":
obs = inp.get("observations")
obs_ok = isinstance(obs, list) and (not obs or isinstance(obs[0], dict))
if (isinstance(obs, str) or "magnitude" in inp or "source_ids" in inp) and not obs_ok:
return {"shape": "flattened", **base}
if not obs_ok:
return {"shape": "other", **base}
else:
if not isinstance(inp.get("main_observation"), str) or "observations" in inp:
return {"shape": "other", **base}
return {"shape": "missing_required" if missing else "conforms", **base}
def submit_batch():
reqs = [{"custom_id": f"{m}__{s}__{j}", "params": _params(m, s, j)}
for m in MODELS for s in SCHEMAS for j in range(N_PER_CELL)]
b = _client().messages.batches.create(requests=reqs)
print(f"batch_id={b.id} n={len(reqs)}")
def report_batch(batch_id):
c = _client()
rows = []
for line in c.messages.batches.results(batch_id):
m, s, j = line.custom_id.split("__")
if line.result.type != "succeeded":
rows.append({"model": m, "schema": s, "result": line.result.type}); continue
msg = line.result.message
blk = next((x for x in msg.content if x.type == "tool_use"), None)
rows.append({"model": m, "schema": s, **_classify(blk.input if blk else None, s)})
_summary(rows, "batch")
def sync():
c = anthropic.Anthropic()
rows = []
for m, s in [("claude-opus-4-8", "nested"), ("claude-opus-4-8", "flat"),
("claude-opus-4-7", "nested")]:
for j in range(N_SYNC):
r = c.messages.with_raw_response.create(**_params(m, s, j))
msg = r.parse()
blk = next((x for x in msg.content if x.type == "tool_use"), None)
cl = _classify(blk.input if blk else None, s)
rows.append({"model": m, "schema": s, "request_id": r.headers.get("request-id"), **cl})
print(f" {m}/{s}#{j} -> {cl['shape']}{' [LEAK]' if cl.get('xml_leak') else ''}")
_summary(rows, "sync")
def _summary(rows, transport):
cells = {}
for r in rows:
cells.setdefault((r["model"], r["schema"]), Counter())[r.get("shape", r.get("result"))] += 1
print(f"\n{'model':18} {'schema':7} {'transport':9} shapes")
for (m, s), cnt in sorted(cells.items()):
leak = sum(1 for r in rows if r["model"] == m and r["schema"] == s and r.get("xml_leak"))
print(f" {m:18} {s:7} {transport:9} {dict(cnt)} xml_leak={leak}")
if __name__ == "__main__":
cmd = sys.argv[1] if len(sys.argv) > 1 else "submit_batch"
{"submit_batch": submit_batch,
"report_batch": lambda: report_batch(sys.argv[2]),
"sync": sync}.get(cmd, lambda: print(__doc__))()
Confirming the nested array
After flattening to {criterion_scores: list[str], numeric_scores: list[float], rationale_texts: list[str]}, the failures went to zero. That confirms ffishman's trigger isolation — it's specifically the array<object> nesting that causes it, not batching per se.
For the 4.8 <parameter name="..."> XML markup contamination variant: this appeared for us as the rationale_texts field coming back with <parameter name="rationale_texts"> as a prefix string, making the Pydantic validator reject the field as non-string. The field before it was correctly populated, and the contamination consumed the sibling field as ffishman describes. The contaminated string is parseable if you know the format, but it's clearly model internals leaking.
Server-side fix is the right direction. SDK-side detection/retry would be useful as belt-and-suspenders while the server fix ships: check for <parameter name= in any string field value or a missing required field, and if found, re-issue as messages.create (synchronous) which doesn't trigger the contamination.
Hey @ffishman thanks so much for all the details! We're actually still not able to reproduce this internally. Any chance you could share a batch or request ID where you saw this so I can dig a bit more internally?
Absolutely — request-ids below, including fresh ones from today (2026-06-10, the bug still reproduces). All on SDK 0.104.1, anthropic-version: 2023-06-01.
Fresh reproductions (today, 2026-06-10)
8 sync messages.create calls on claude-opus-4-8, nested schema, ~15K-token input → 3/8 contaminated:
| request-id | output tokens | result |
|---|---|---|
req_011CbuxWxTt9x85k9xPaujHP |
2022 | contaminated, strength swallowed |
req_011CbuxYQYZ1dPhp5Y2ajd1c |
1070 | contaminated, strength swallowed |
req_011CbuxcPdMGMLH2uT5utss3 |
2008 | contaminated, strength swallowed |
req_011CbuxUTjvozqB5ewiGZdWL, req_011CbuxVXPUaYxn3u42fGqTu, req_011CbuxZPqfcQGJBykJWX8nD, req_011CbuxamFYyJyJPn6Gv8Shy, req_011CbuxdtnZj2eVeyVoY1QL1 |
— | clean controls |
Original request/batch IDs (2026-05-29, table in my earlier comment)
- opus-4-7 batch (single-key wrap): batch
msgbatch_01AwVjNuJd2ArCCe66MBRhMn·req_011CbWxBJyGeRQpdBQZUYTo7 - opus-4-8 batch (XML leak): batch
msgbatch_01FnyZXPXe8QD9oFCorGTXpt·req_011CbWxBR6NeLnd9r6cXSVpH - minimal-repro batch (script above): batch
msgbatch_01G95b3JkAduXgDUkbKop8Ya·req_011CbWy82QeUZU2zwThvFbUs - opus-4-8 sync, contaminated:
req_011CbWyDPzZua8C9RjgpqUvd - opus-4-7 sync, wrapped in
"report":req_011CbWySM54Vmfhptm9jCpPu - opus-4-8 sync, clean control (nested):
req_011CbWy9L4ZthwLhDLTvRm2M· flat clean:req_011CbWyFYaZ98fCQqfFtmVNM
Patterns that may explain why it's not reproducing internally
1. The contamination is deterministic, not noise. All 6 contaminated samples (3 from May, 3 from today) have a byte-identical signature: the long free-text field (summary) ends with literal markup plus the value of the swallowed sibling inline —
"...do timing da dose e do estado alimentar.</parameter>\n<parameter name=\"strength\">consolidated"
— and the key strength is missing from the object. It's always the same boundary: end of the first long string field → the enum sibling that follows it in schema property order. The leak always sits ~8-11% into the serialized JSON.
2. The 4.7 wrapper key derives from the tool name — it's not a random hallucination. In the minimal repro, tool save_report → wrap key "report" in 6/6 wrapped cases. In our production pipeline, tool save_topic_synthesis → "topic" / "input" / "$PARAMETER_NAME". This points at the internal tool-call serialization template: the model appears to emit the call in an internal XML-ish format (<parameter name="...">) and the transcoding to JSON misfires on the parameter-name placeholder.
3. Output length matters (at least on 4.7). In the wrapped 4.7 batch cells, broken samples averaged ~3.5K output tokens vs ~1.6K for clean ones. If internal repro prompts elicit short tool calls, the bug may never trigger. On 4.8 the correlation is weaker (one of today's contaminated runs was only 1070 output tokens), so the full recipe is: nested array<object> sub-schema + forced tool_choice + ~15K-token input + a prompt that elicits a long-ish summary field + n≥8 per cell (batch reproduces at a higher rate than sync).
Generational note: claude-fable-5
On claude-fable-5, forced tool_choice is rejected outright — both {"type": "tool", ...} and {"type": "any"} return 400 ("tool_choice forces tool use is not compatible with this model"), so the bug's trigger surface doesn't exist there. With tool_choice: auto + a strong always-call instruction: 24/24 clean (8 sync + 16 batch, same schemas/input sizes). So the issue is bounded to models that still accept forced tool_choice — opus-4-7 and opus-4-8 both still reproduce as of today.
Happy to run more cells or share full raw response bodies if useful.
Adding a reproduction that broadens the trigger surface beyond what's been isolated so far: model: claude-sonnet-5, and notably without any of the three ingredients in the current repro recipe (no nested
array<object>, small input, and it also reproduces without forced tool_choice).
Setup
claude-sonnet-5, non-streamingmessages.create, TypeScript SDK0.109.0tool_choice: {type: "tool", name: "..."}(forced), nostrict, nothinkingparam,output_config: {effort: "medium"}- Small prompt: ~1.7K tokens total (system + user), no few-shot examples, German-language text output
- Tool schema: no
array<object>anywhere. Field names below are anonymized; structure, types, therequiredset, and property order are exact:
{
"type": "object",
"required": ["label", "variants", "body", "abstract", "meta_text", "keywords"],
"properties": {
"keywords": { "type": "array", "items": { "type": "string" } },
"label": { "type": "string" },
"body": { "type": "string" }, // long free-text HTML, typically 5–6K chars in output
"abstract": { "type": "string" },
"variants": {
"type": "object",
"required": ["primary", "alt_a", "alt_b"],
"properties": {
"primary": { "type": "array", "items": { "type": "string" } },
"alt_a": { "type": "array", "items": { "type": "string" } },
"alt_b": { "type": "array", "items": { "type": "string" } }
}
},
"meta_text": { "type": "string" }
}
}
Results (2026-07-13, two distinct real-world inputs, same-day runs)
| model | tool_choice | conforming | broken |
|---|---|---|---|
| sonnet-5 | forced | 8/12 | 4 × required label missing |
| sonnet-5 | auto + "respond only via the tool" instruction |
6/8 | 2 × required label missing |
| sonnet-4-5 | forced (identical requests) | 6/6 | — |
Two additional forced batches earlier the same day (before we captured request-ids) showed the same rates: 4/12 and 2/8. Aggregate across the day: forced 8/24, auto 4/16. claude-sonnet-4-5 has been 0-for-everything on
identical requests, consistent with our testing since early July.
Failure signature
- The required
labelkey (a short string field) is absent fromtool_use.input;stop_reasonistool_useand the rest of the object is complete and coherent — it passes shallow structural checks. - A value that clearly belongs to the missing field materializes as the sole element of the first
array<string>inside the nested object (variants.primary) — i.e. the dropped field's content migrates into the next
nested container rather than disappearing. - In 3 of the 6 broken samples, a spurious non-schema key appears, derived from one of the real field names with a
2/_checksuffix, containing junk ("placeholder","ok"). This looks related to the
invented-wrapper-key behavior described above for opus-4-7. - In production runs on 2026-07-01 we additionally saw the opus-4-8-style variant on sonnet-5: raw
<parameter name="...">markup leaking into string field values, at ~30–50% during a bad window (whole batches clean, whole batches broken — strongly time-windowed). One of today'stool_choice: autoruns also leaked markup into a string field (that run predates our request-id capture).
Request IDs (all 2026-07-13, sync messages.create)
Broken — forced tool_choice, required field missing:
req_011CczfsUdQf4TjS6A9rTRoGreq_011CczfurmyYMfGXwNtTtMy2req_011CczfxwSr9iTMkwEUJfobx(also has a spurious non-schema key)req_011CczfyasNd1MXcGvTedPjK(also has a spurious non-schema key)
Broken — tool_choice: auto, required field missing:
req_011Cczg6EMHE6obTWvNvqTFQreq_011Cczg9gv38YSyK9UtodWPy(also has a spurious non-schema key)
Clean controls, same request shape: req_011Cczfp8qhSS2tH6FtSDKtP (forced), req_011Cczg37oZ6pnD9frRTZH2t (auto).
Why this may matter for triage
Relative to the recipe isolated above (nested array<object> + forced tool_choice + ~15K-token input + long outputs):
- No
array<object>— a nested plainobjectcontainingarray<string>properties plus one long free-text string field is sufficient. - Small input — ~1.7K tokens, an order of magnitude below the ~15K in the repro script.
- Forced
tool_choiceis not required —auto+ an instruction reproduces at a similar rate on sonnet-5 (unlike the fable-5 observation above where auto was clean). - Reproduction rate is high (~25–33%) and stable across days/batches, so n=8–12 per cell is enough to see it.
Happy to run more cells or share full sanitized response bodies if useful.
@ffishman sorry for the slow follow-up, and thanks again for the reproducer and request-ids. Re-running your repro_minimal.py today I get 0/16 malformed tool inputs: claude-opus-4-7 3/3 clean in batch and 3/3 sync, claude-opus-4-8 3/3 batch and 3/3 sync, and @sevsh's claude-sonnet-5 shape 4/4 clean. If either of you can still trigger it with the same script, could you drop one fresh request-id here?
Re-tested today (2026-08-06) with SDK 0.120.2, across every cell that ever had a
documented break rate. 75 samples, zero reproductions. Reporting the negative
result since it's mine to report.
| cell | model / schema / transport | n | broken | historical rate | P(all clean if unchanged) |
|---|---|---|---|---|---|
| A | claude-opus-4-7 / nested array<object> / batch |
7 | 0 | 6/8 (75%) | 0.006% |
| B | claude-sonnet-5 / @sevsh shape / sync, forced |
12 | 0 | ~33% | 0.8% |
| B' | claude-sonnet-5 / @sevsh shape / sync, forced + output_config:{effort:"medium"} |
12 | 0 | ~33% | 0.8% |
| C | claude-sonnet-5 / @sevsh shape / batch, forced + effort |
12 | 0 | ~33% | 0.8% |
| D+E | claude-opus-4-8 / nested array<object> / batch |
32 | 0 | 2/8 (25%) | 0.01% |
Aggregated: 36 sonnet-5 samples against @sevsh's ~33% rate is 6e-7; 32 opus-4-8
samples against 25% is 1e-4. These aren't underpowered runs.
Batches: msgbatch_01417psTwb44ryQiy7r4zZMQ (A), msgbatch_01L7MBzxty8enEP3QLeatRKj
(C+D), msgbatch_01NZBCeKZ77G4273j6Nmbjh6 (E). Cell A is my repro_minimal.py
unchanged; D/E use the same schema and params via batch.
Notes on the cells
- Cell A: 7/7 conforming. One sample excluded rather than counted —
stop_reason=max_tokens, output exactly at the 6000 cap,input={}. That's truncation, not this bug; my first pass miscounted it because the classifier in the published script doesn't checkstop_reason. Mentioning it only because it's an odd outlier:msg_011CdnEjwAdUVWvXREby1ZBiran to the full 6000 tokens where its 7 siblings finished at 2283–3655. I can't inspect it (partial JSON comes back as{}), so I'm not claiming it's related. - Cells B/B'/C: schema structure, types,
requiredset and property order are @sevsh's exactly; the prompt is my reconstruction of "long German free-text body", not their real input. Output was 4140–5134 tokens throughout, so the long free-text field was genuinely elicited. Still a weaker negative than the cells where the artifact was mine to begin with. - Cells D+E:
opus-4-8is where my most recent reproduction was (3/8 sync on 2026-06-10), so I ran it to n=32 rather than leave it at the n=8 I started with — at 25%, n=8 would have had a 10% chance of coming back clean with the bug fully intact, which wouldn't have been worth reporting either way.
So: the recipes as documented do not reproduce today, and your read was right — though 3/cell wouldn't have distinguished that from the bug still being live.
Two things before I'd call it settled:
1. Could you check the stored responses for the request-ids already in this thread,
rather than needing fresh ones? From my 2026-06-10 run: req_011CbuxWxTt9x85k9xPaujHP,
req_011CbuxYQYZ1dPhp5Y2ajd1c, req_011CbuxcPdMGMLH2uT5utss3. From @sevsh on 2026-07-13:
req_011CczfsUdQf4TjS6A9rTRoG, req_011CczfurmyYMfGXwNtTtMy2, req_011CczfxwSr9iTMkwEUJfobx,
req_011CczfyasNd1MXcGvTedPjK, req_011Cczg6EMHE6obTWvNvqTFQ, req_011Cczg9gv38YSyK9UtodWPy.
Whether the raw output for those contains the unclosed <parameter name=...> markup is what
distinguishes "the transcode path was fixed" from "a bad deployment was rolled back" —
and only the second one can come back.
2. @sevsh reported this as strongly time-windowed — ~30–50% during a bad window on 2026-07-01, near-zero outside it. If that's right, no single clean day is evidence about the code path: not their clean controls, not your 0/16, not my 75/75. That's the main reason I'd rather have the log answer than more sampling from my side.
One thing worth recording regardless of status, since this thread reads as three separate bugs and I think that framing has been costing the triage. All five reported symptoms are boundary or substitution errors consistent with a single XML-ish → JSON transcode step:
| symptom | reading |
|---|---|
$PARAMETER_NAME as the wrapper key |
template placeholder never substituted |
wrapper key derived from the tool name (save_report→report, save_topic_synthesis→topic) |
placeholder substituted with the wrong target |
<parameter name="X"> leaking mid-string, next sibling missing |
closing </parameter> boundary lost, parser keeps consuming |
a required field's value relocating into the first nested array<string> (@sevsh) |
same lost boundary, attributed to the wrong container |
spurious field2 / field_check keys holding "placeholder" / "ok" |
template scaffolding leaking |
And the original recipe eroded over the course of the thread: large input fell (@sevsh: ~1.7K
tokens), nested array<object> fell (a plain nested object with array<string> properties
suffices), batch-only fell (I corrected that myself), forced tool_choice fell (@sevsh
reproduces on auto). The only invariant left across every report is a schema with a
nested container plus at least one long free-text string field. If this ever resurfaces,
that's the recipe worth regression-testing, not any of the narrower ones.
@sevsh — sorry for not replying back in July. Your report broadened this materially and I let
it sit. My cells B/B'/C above are only an approximation of your case, since I don't have your
actual input; if you still have what produced req_011CczfsUdQf4TjS6A9rTRoG, re-running that
is the one test that would settle your half properly.
@dtmeadows-ant sorry for the long silence, and thanks for re-running my shape. You asked for a fresh request-id if either of us could still trigger it. We can, today (2026-08-11).
It still reproduces on claude-sonnet-5 with the shape I posted in July: flat schema, small input (~1.5K input tokens), forced tool_choice, output_config: {effort: "medium"}, non-streaming messages.create, TypeScript SDK.
| model | TS SDK | malformed |
|---|---|---|
| claude-sonnet-5 | 0.109.0 | 6/12 |
| claude-sonnet-5 | 0.116.0 | 2/12 |
| claude-sonnet-4-5 | 0.109.0 | 0/6 |
| claude-sonnet-4-5 | 0.116.0 | 0/6 |
Pooled sonnet-5: 8/24 = 33%, exactly the rate I reported in July. The gap between the two SDK versions is not significant (Fisher exact, two-sided, p = 0.19) - I would not read it as an SDK effect.
The failure shape changed since July: no XML markup leaks this time. tool_use.input simply comes back missing the required title, every other field present and well-formed, stop_reason: "tool_use" (not truncation) - the "required field disappears while the object still looks well-formed" mode from earlier in this thread. Two variants on top: one response returned headlines as a JSON-encoded string with summary/seoDescription/tags all absent (sibling swallowing); one carried an extra non-schema key content_check: "ok" alongside the missing title.
Fresh request-ids, all 2026-08-11 — SDK 0.116.0, claude-sonnet-5, malformed: req_011CdviFirxwh1cv8TpQdAbo (missing title + extra content_check), req_011CdviKPaDcFrtKPEebkgbq. SDK 0.109.0, claude-sonnet-5, malformed: req_011CdvhjxyhX1doSkKwgUcND, req_011Cdvhjxzgg81HwfHVn4LFr, req_011CdvhrNv2P39saFQAb6pjc, req_011CdvhrRQ6g51Dc6RBoh3BZ (headlines-as-string), req_011CdvhuC8iHWRXAcSdXnzTv, req_011CdvhuWvZxrEoqn2ZxW6dv.
Clean controls from the same runs, in case the contrast helps: sonnet-5 clean req_011CdviCbsCPsreMPjmggFSV, req_011CdvhjxxhyJg3FcfHGcSoB; sonnet-4-5 clean req_011CdviSqgHysasprwoDBJxp, req_011Cdvhyux2NT331SSdXrmeE.
Happy to share the exact request payload privately if that helps. This might be worth reopening.
@sevsh thanks, this is exactly what I needed. I can reproduce the pattern on our side now with your shape on claude-sonnet-5 (a required field dropped and tool-call markup inside a string value, at a lower rate than you're seeing). It isn't coming from the SDK — the response arrives that way — so I've reopened this and passed the request-ids along. If you're able to share the exact payload privately that would help narrow the rate difference; I'll follow up here.
@dtmeadows-ant thanks for reopening, and for reproducing it. I went looking for the rate difference
you mentioned. I found its source, and along the way two levers that change the failure rate by more
than an order of magnitude with everything else byte-identical.
Short version of the rate difference: what you ran as "my shape" was a reconstruction from my July
comment, and that comment only ever contained the anonymized schema, not the payload. That
reconstruction is clean for me too - 0/12. The trigger is in the part I did not publish.
All numbers: claude-sonnet-5, TypeScript SDK 0.116.0, non-streaming messages.create, forced
tool_choice, output_config: {effort: "medium"}, max_tokens: 12288, 2026-08-12, 252 samples,
zero API errors. "Synthetic prompt" throughout means a generic German tech-magazine editor prompt I
wrote for this test (~1.7K tokens, invented news items, no few-shot); it shares no wording with my
production prompt.
Lever 1: the name of the nested container
My schema has a nested object property holding three arrays of headline variants. The required
top-level string that goes missing sits immediately before it.
| change to my schema (synthetic prompt, everything else identical) | malformed |
|---|---|
| none | 12/12 |
| all nine property names anonymized | 1/12 |
| only the name of the missing field changed | 9/12 |
| only the nested container renamed, its three children untouched | 1/12 |
Renaming the container fixes it. Renaming the field that actually disappears does not. That is
consistent with the migration behaviour described earlier in this thread - the dropped value moves
into the following container - but it locates the sensitivity on the container, not the victim.
Lever 2: the position of the long free-text property
7 of the first 8 markup leaks I saw landed in the property immediately after the long free-text
one. So I moved the long property to the end of properties and required, expecting the leak to
have nowhere to spill. The opposite happened.
| production configuration (my real prompt and schema) | malformed |
|---|---|
| unchanged | 5/12 |
| nested container renamed | 0/36 |
| container renamed and long property moved last | 17/24 |
0/36 vs 5/12: p = 4.6e-04. 17/24 vs 0/24: p = 1.6e-07. The only difference between the last two rows is the position of one property in two lists.
Two things worth flagging from that table. First, the rename removed the markup-leak mode as well, which I did not expect: with my real prompt that mode ran at 6/36 = 16.7% before and 0/36 after (p = 0.025). Second, a schema tidy-up that reorders properties can take this from 0% to 71% silently.
What I could not build, four times
I tried to reduce this to something synthetic I could paste here. Every attempt is clean:
| published anonymized schema + synthetic prompt | malformed |
|---|---|
| as published | 0/12 |
+ the same constraints my schema carries (minItems/maxItems on the arrays, maxLength on one string) |
0/12 |
| + 9 invented German descriptions at the 9 positions mine has them | 0/12 |
| + the long property moved last (lever 2 applied to it) | 0/12 |
| pooled | 0/48 |
The only public-schema cell that ever failed is public schema + my real prompt: 3/12, all markup
leaks. So every failing cell contains something of mine - my schema or my prompt - and neither lever
reproduces on a clean-room schema. Removing all description fields from my own schema also takes it
to 0/12, so the descriptions are necessary too, but substituting invented ones does not restore it.
I do not have a mechanism that explains all of this. What the data says is narrower: the failure needs my actual payload, and given it, container naming and property order each swing the rate between roughly 0% and 70%.
Two failure modes, two drivers
Counting every sample by which half was mine (schema variants count as "my schema", prompt variants as "my prompt"):
| failure mode | my schema | published schema | my prompt | synthetic prompt |
|---|---|---|---|---|
required field absent from tool_use.input |
46/192 | 0/60 | 10/96 | 36/156 |
<parameter name="..."> markup inside a string value |
21/192 | 3/60 | 22/96 | 2/156 |
Dropped field vs schema: p = 1.3e-06. The dropped field has never once occurred on the published schema, across 60 samples and four variants of it.
Early on these dissociated cleanly - dropped field tracked the schema, markup leak tracked the prompt. Lever 2 breaks the second half: moving one property produced 16 markup leaks from a schema change alone, with my prompt held constant. If both modes are one mechanism, container naming and property position are two knobs on it.
Request IDs
Container renamed, production configuration, all clean (a sample of the 36):
req_011CdxWSbXcJ52nhPiAw8Prp, req_011CdxWSbZbFVEai5EdqXw3u, req_011CdxWSbkWE1rkkcxcy5DYt
Container renamed and long property moved last - broken:
req_011CdxXtEYdratbf3yzfSvHc, req_011CdxXtEcMhAayPmm7ibtFF, req_011CdxXtEcrKmxcSydKyNzxV,
req_011CdxXw1b7UDsSkTpbpFtXe, req_011CdxXz3PLugQSN2xcLdgcJ (leak in the long property itself),
req_011CdxY9aReA8n13Lb8s6P8o (long property absent entirely)
Unmodified schema + synthetic prompt, all twelve broken, all "required field absent":
req_011CdxPpPsBHBHhC2BpGRbP3, req_011CdxPpghTPWLqQ3KsUunbY, req_011CdxPpnjMTUFZt9q89FMAG,
req_011CdxPrTJcLZDBUKndouPo8, req_011CdxPrZ4dbmPPgdpySsYX9, req_011CdxPrp9EduKfpxvsa9Cm3,
req_011CdxQKGHKyjMFH56NcaHyA, req_011CdxQKGGb85sLrUVVSguXu, req_011CdxQKGGqAvRnK5qrbWRMD,
req_011CdxQMHBTXEzjDMqPMr1g7, req_011CdxQMGX2ME9Nx4WqczzjG, req_011CdxQMUUN323pzR2PswYk2
Container renamed, synthetic prompt, clean: req_011CdxWejHGt5gXzhVNbAeHc
Published schema + constraints + long property last, clean: req_011CdxYcWAf9t8u33TAXJ7f8 is the one
exception in that direction - a single markup leak on the published schema during a warm-up call,
which the 12-sample run that followed did not repeat (0/12). I am reporting it because it is the only
public-schema failure I saw outside the real-prompt cell, not because it reproduces.
On the payload
The consequence for you: my tool schema alone reproduces this at 12/12 with a prompt that is not mine, and the two levers above are properties of that schema. You do not need my prompt.
I would rather not put the schema in a public thread. You mentioned sharing privately - what channel would you like? I did not find one on your profile, and a support ticket referencing the request-ids above would work for me if that is the right route.
One thing I have not tested and am not claiming: whether any of this transfers to the opus models discussed earlier in the thread.
@sevsh thanks for all the extra details. I'm digging into this further internally and will post back here when I know more.
@dtmeadows-ant one correction to my previous comment, and one new datum that may be useful while you are looking internally. Neither requires anything from you.
Correction
I wrote that renaming the container removed the markup-leak mode as well (6/36 → 0/36 with my real prompt, p = 0.025). That does not hold up. With 103 renamed calls instead of 36, leaks still occur at 3/103 = 2.9% (95% CI 1.0–8.2%). The 0/36 was substantially luck. The sentence as written describes the cell I measured, but the generalization a reader would draw from it — "the rename fixes both modes" — is not supported. Only the dropped-field mode is fixed. If you were treating "one change removes both modes" as a clue to a shared mechanism, please drop it.
The rename generalizes across sibling schemas — for one mode only
My previous numbers came from a single schema. I have now run four more from the same family (same generator, same six-property shape, same nested container, different descriptions and constraints), synthetic prompt throughout.
Interleaved design: control and renamed calls alternate call-by-call rather than running as two blocks. This matters — see the note at the end.
| schema | unchanged | container renamed | Fisher p |
|---|---|---|---|
| A | 6/12 | 0/12 | 0.014 |
| B | 7/12 | 0/12 | 0.0046 |
| C | 9/12 | 0/12 | 0.0003 |
| D | 1/12 | 1/12 | 1.0 |
| pooled | 23/48 | 1/48 | 1.2e-07 |
Schema D's control barely fired in this window, so that row is underpowered, not evidence of an exception.
Split by failure mode within this run:
| mode | unchanged | renamed | p |
|---|---|---|---|
| required field absent | 19/48 | 0/48 | 4.1e-07 |
<parameter name="..."> markup in a string |
4/48 | 1/48 | 0.36 |
Across every renamed call I have made (103, several sessions): field absent 0/103, markup leak 3/103. Two of the three leaks are in the same schema (A), the third in D. Request-ids, all renamed configuration, all leaks in the long free-text property:
req_011CdxgcZT2wRRTxMZYQJNiF, req_011CdxghEtUFdwdj2BHbZ3uk, req_011Cdxjy3XeCA7ND9cqRBxPx
So the two modes separate again, but on a different axis than in my last comment: container naming drives the dropped field and does nothing measurable to the leak.
Why interleaving, and a note on your rate difference
I first ran this as two blocks, renamed after control. The renamed arm came out at 2/48 and the control arm — same schemas, same prompt, ~40 minutes later — at 1/12 where the earlier measurement predicted 4.8. P(X ≤ 1) = 0.013 under the rate I had measured that afternoon. The base rate moves between blocks: I see whole runs clean and whole runs broken with byte-identical inputs. I threw that comparison out and re-ran interleaved; the numbers above are from the interleaved run, whose control landed at 23/48, inside the band I had pre-stated for it.
I mention it because you observed the pattern "at a lower rate than you're seeing". Part of that gap may simply be when the samples were taken. If you are comparing arms, interleaving them is cheap insurance.
Payload
Unchanged from my last comment: happy to share the schema through whatever channel suits you, no urgency. Everything above is reproducible without it on your side via the request-ids.