Updated October 29, 2026. An earlier version of this post said that value-lock had caught truncated outputs, that reliability degraded gradually with batch size, and that our size limit was derived from calibration testing. We could not reproduce the first two when we re-tested, and the limit is a conservative choice rather than a measured boundary, so we rewrote those sections around what we measured.
Quick Reference
The short version: An AI repair tool can fail loudly (an error, an empty response) or quietly (a plausible-looking but wrong result). The loud kind is easy to handle; the quiet kind is the one to design against.
What we measured: when a repair is too big for the model's output budget, we got an empty response, not a wrong one. Our answer: a conservative size limit, value-lock where a baseline of your data exists, schema validation, and one rule that governs all of them: reject rather than silently corrupt.
Most discussions about AI reliability focus on accuracy — did the model get the right answer? That's the wrong question for a repair tool. The right question is: when the model is wrong, how does your system find out, and what does it do next?
This post covers what we measured when the model runs out of room, and what our two main guardrails do about it.
1. The Problem: When "It Worked" Isn't Good Enough
Our AI-assisted repair endpoint exists for one reason: rule-based JSON repair can fix syntax, but it can't fix semantics. If a field says status: "urgent" and your schema only allows ["low", "medium", "high"], no regular expression is going to figure out that "urgent" probably means "high." That takes a language model.
A language model does not always manage it, though. In our tests of this kind of mapping (records with a status field, and a schema listing the allowed values), only 2 of 8 runs with 50–200 records completed the mapping. In the other six the model returned the original values unmapped or dropped the field, and schema validation rejected those repairs. Treat enum mapping as best-effort: when the model doesn't complete it, schema validation rejects the repair instead of returning it.
Handing a semantic decision to a language model is a reasonable trade. Handing it a decision with no way to verify the result is not. Most JSON repair tools — including the open-source rule-based libraries this space is full of — don't need to worry about this, because they don't touch semantics at all. The moment you add an AI model into a repair pipeline, you've added a component that can be confidently, plausibly wrong.
We already had guardrails against this: when your schema lists required top-level fields, the engine rejects a repair that invents one that was missing from the input, and when it can build a baseline of your original data it rejects a repair that changes a protected value. The question we had not answered with data was what happens when the model runs out of room mid-repair.
2. What We Measured: Running Out of Output Budget
Language models don't generate output all at once — they generate it token by token, against a finite output budget. A repair has to write out the whole document again, so the output grows with the input. Our endpoint gives the model at most 4,096 output tokens per call.
So we asked what happens when a repair is too big to fit. In October 2026 we sent synthetic arrays of small records that the rule-based cleaner could not fix (no schema) and compared each response with the known-correct result. Inputs of 7.7–8.7 KB came back correct in 20 of 20 runs, and smaller ones (2–7 KB, plus two runs at about 9.1 KB) were correct every time, though we ran only a few at each of those sizes. At 9.5–10.5 KB none did (0 of 20), and neither did four runs at 18–20 KB: the model reached the 4,096-token cap and returned no content. Our endpoint reports an empty response as an error and charges 1 credit, because the model did run. With long text fields instead of short records, 12 of 12 runs were correct up to about 12 KB (counting a trimmed trailing space as correct). The boundary moves with the data — the two shapes needed different numbers of output tokens per input byte — and we have not tested other kinds of data, such as non-ASCII text or numeric-heavy records. The tests called the repair code directly, with the same model and prompts as production, over the Workers AI REST API rather than the production binding.
The failure that matters most for a repair tool is a quiet one: a response that looks complete but quietly rewrote content you never asked it to touch. An empty response is annoying but obvious — you retry. A quiet one is the kind of bug that ships into production, gets logged as "success," and surfaces three weeks later as a data integrity incident nobody can explain. We looked for it and did not find it: in these runs, every response that hit the cap was empty, and none came back looking complete. That is a measurement on a limited set of data, not a guarantee, and it is why the guardrails below stay in place.
3. Two Guardrails, Not One
We rely on two independent checks that cover different failure shapes.
3.1 Value-Lock
When we can build a baseline of your original data, the AI's output is compared with it field by field. The model is only permitted to fix structure and — only when your schema declares an enum at that path — remap a value to one the schema allows. Any other scalar that comes back changed causes the entire repair to be rejected, not silently accepted with a footnote. There are two limits. If neither the rule-based cleaner nor a direct parse can recover a baseline (typical for severely malformed text), value-lock cannot run for that request, and only the JSON-validity and schema checks apply. And the comparison follows properties and items only: a key the model deletes or renames is not flagged.
{
"success": false,
"error": "AI repair rejected: changed protected value(s) at accountType"
}Value-lock checks what the model returns, not why it went wrong. In the size tests above it had nothing to reject: responses that ran out of budget were empty, so there was nothing to compare. Where it earns its place is the case we are guarding against — a complete-looking response whose values differ from your input.
3.2 A Conservative Batch Limit
Value-lock checks output after the fact. The second guardrail keeps requests away from the condition where the model runs out of room: input to our AI repair endpoint is capped at 3,072 bytes, far below the platform's general 1 MB payload limit. That cap is a deliberately conservative product limit, set well under the point where we saw repairs fail (roughly three times lower for the data we tested), not a measured failure boundary.
{
"success": false,
"error": "Input exceeds the AI repair size limit (3072 bytes; received 5880 bytes). Please split large inputs into smaller batches and repair them separately."
}Oversized input never reaches the model at all. It's rejected immediately, before any AI call is made — which also means it's never charged. If you need to repair a larger document, the answer is to split it into smaller batches, not to hope the model handles the whole thing correctly.
4. The Trade-Off We Chose — And Who It's For
We want to be direct about what this costs: some requests that a more permissive system would "handle" get rejected by ours. A batch that's a little too large doesn't get a best-effort attempt — it gets a 413 and a suggestion to split it up.
We think that's the right trade for the kind of integration this tool is built for. If you're feeding repaired JSON into a database, a billing pipeline, or anything downstream that assumes the data it receives is correct, a loud, immediate rejection is far easier to handle than a quiet, delayed corruption. You can catch a 413 in your error handling in five minutes. You cannot easily catch "some records in this batch have subtly different field values than what was submitted," because nothing told you to look.
If what you need instead is a tool that always returns something and you're comfortable spot-checking the output yourself, that's a legitimate choice too — it's just not the trade-off we made here. We'd rather tell you no than tell you a wrong yes.
5. The Principle Behind It
This isn't an isolated fix. It's the same rule that already governs how this platform handles numeric precision: JSON's number type can't exactly represent values beyond about 15 significant digits, and rather than silently round a value that exceeds that and hand back a number that's quietly wrong, every endpoint on the platform rejects the input outright.
Precision guarding, value-locking, and a conservative batch limit are three implementations of one idea: reject rather than silently corrupt. None of them make the underlying language model more accurate. What they do is make sure that when it isn't accurate, you find out immediately — not after the bad data has already gone somewhere it shouldn't have.
Want to see how this plays out in practice? The AI-assisted JSON repair tool and its full API documentation — including the Guardrails section — are free to try, no login required.