ResearchMay 4, 2026

When correct isn’t
usable.

Small language models often get the answer right and still return something a program can’t read. We measured that gap on two math benchmarks, then closed most of it without touching the weights, by letting an optimizer watch each model fail and rewrite its system prompt.

When Correct Isn't Usable: Improving Structured Output Reliability in Small Language Models · arXiv:2605.02363

Cosimo Galeone, Minsu Park, Giuseppe Ettorre, Daniele Ligorio
0%
output accuracy without a system prompt, at up to 85% task accuracy
84–87%
output accuracy with AloLab on GSM8K, across three open 7–9B models
3.6–8.2×
the latency of constrained decoding, which still scores lower
29 / 30
runs significantly better than a hand-written prompt

01Right answer, unusable output

A model in production answers to two judges. The first checks whether the answer is right. The second is a parser, and it only checks whether the response has the agreed shape. Fail the parser and the answer never arrives, however good it was. Most benchmarks only ask the first question.

The failure is easiest to see in one example. Asked for JSON, Gemma 2-9B solves the problem, writes a clean object, and then wraps it in a markdown code fence. To a human reader the fence is harmless; to JSON.parse it is a syntax error. Switch the prompt below and the parser runs live in your browser.

Gemma 2-9B IT · GSM8K
System prompt
You are a math expert. Solve the problem step by step, then give the final numeric answer.
Respond with a JSON object with keys “reasoning” (string) and “answer” (number).
Model output, as written
```json
{
  "reasoning": "Janet uses 3 eggs for breakfast and 4 for muffins, leaving 9 to sell at $2 each: 9 x $2 = $18.",
  "answer": 18
}
```
JSON.parse → SyntaxErrorUnexpected token '`', "```json { "... is not valid JSON
The verdict on the right comes from your browser’s own JSON.parse, run on the text shown. Under the Reference prompt the answer is right and the response is still unusable, on every one of the 1,319 GSM8K test samples (json_valid = 0%). The Optimizer’s epoch-2 rules took validation output accuracy from 0% to about 80%. The right-hand output in the second view is the paper’s example with the fence removed, for illustration, not a logged response.

We call the joint condition output accuracy: the answer is correct and the response is valid JSON with every required field. It is the primary metric throughout this work, and a harder bar than it sounds. §2.2

02A controlled test bed

We use mathematics as an instrument, not as the subject. A math problem has one checkable answer, so a mistake in reasoning can never be confused with a mistake in format. We pair it with a strict contract: a JSON object with a reasoning string and a numeric answer. §1, §2.1

Models
Llama 3.1-8B Instruct, Gemma 2-9B IT and Qwen 2.5-7B Instruct, served as released. GPT-4o joins on GSM8K, to check whether the problem is specific to small models.
Data
GSM8K (1,319 test problems) and MATH (5,000 test problems across seven subjects and five difficulty levels), on fixed, disjoint splits at temperature 0.
Strategies
Naive, no system prompt. Reference, a minimal hand-written JSON prompt, the kind you write before you have watched the model run. Constrained, grammar-constrained decoding. Ref+Constrained, both together. AloLab, our iterative optimizer, run five times per model and dataset.

03The 0% baseline

With no system prompt, every model does respectable math: 77–85% task accuracy on GSM8K. Not one returns a single valid JSON response. Output accuracy is zero for every model on both datasets. The bottleneck is not reasoning. It is format. §4.1

Naive prompting · no system prompt
Task accuracyOutput accuracy
Llama 3.1-8B Instruct
76.88%
0.00%
Gemma 2-9B IT
80.44%
0.00%
Qwen 2.5-7B Instruct
85.10%
0.00%
GPT-4o*
84.30%
0.00%
Table 1. Every model solves a substantial share of problems, and none produces a single valid JSON response. Task accuracy is recovered by a fallback parser that reads the answer from the free text. Output accuracy requires the answer to be correct and the JSON to parse. *GPT-4o was evaluated on GSM8K only.

That changes what “small models can’t do it” often means. The capability is there. It just doesn’t arrive in a form the rest of the system can use.

04Optimizing the prompt, not the model

AloLab treats the target model as a black box. It sees what goes into the inference API and what comes back, nothing more: no weights, no gradients, no labelled demonstrations. Each epoch it runs the current system prompt on a training split, scores every reply, and hands the traces to a stronger model that diagnoses what went wrong and rewrites the prompt. §2.4

The optimization loopafter Figure 1
epoch2/4
01Solverqueries the model, black-box
02Evaluatorjson_valid · is_correct
03Analyzerfailure and success patterns
04Optimizerrewrites the system prompt
Loader · fixed splits4 epochs on validationBest epoch → test set
Each epoch the Solver runs the current prompt, the Evaluator scores every reply, and two meta-agents (Claude Sonnet 4.5) read the results and rewrite the prompt. The checkpoint with the best validation score goes to the test set.

Most of the gain arrives early. On GSM8K, Llama and Gemma converge within two to three epochs. Gemma is the sharpest case: its first epoch scores 0% in all five runs, because the Reference prompt yields fenced JSON. At epoch 2 the optimizer identifies the fence, suppresses it, and output accuracy breaks through in a single step. On the harder MATH set progress is more gradual, and Qwen sometimes takes a wrong turn that later epochs don’t undo. §4.4

Figure 3. Validation output accuracy over optimization epochs.
Six panels, GSM8K on top and MATH below, for Llama 3.1-8B, Gemma 2-9B and Qwen 2.5-7B. Each dot is one run's validation output accuracy at epochs 1 to 4; a line traces the mean.
GSM8K in the top row, MATH below. Each dot is one independent run and the line is their mean. The paper’s plots label output accuracy “usability”. Figure 3, arXiv:2605.02363.

05Five strategies, compared

On GSM8K, AloLab has the highest output accuracy for every model, between 84% and 87%. The hand-written Reference prompt is erratic: 74.3% for Qwen, 44.4% for Llama, and 0% for Gemma, whose fenced replies never parse even though the answers inside are right 88.4% of the time. On MATH the gap widens. Reference is near zero for two of three models, and AloLab is the only strategy that reliably clears 30%. §4.2

Output accuracy, %
Llama 3.1-8B Instruct
Naive
0.00
Reference
44.43
Constrained
52.46
Ref+Constrained
19.56
AloLab
84.15[83.71, 84.59]
Gemma 2-9B IT
Naive
0.00
Reference
0.00
Constrained
15.31
Ref+Constrained
22.90
AloLab
87.41[87.10, 87.70]
  • Reference: Gemma wraps every JSON response in markdown fences, so nothing parses. The fallback parser recovers 88.4% task accuracy.
  • Constrained: 52.4% of outputs are exact duplicates.
Qwen 2.5-7B Instruct
Naive
0.00
Reference
74.30
Constrained
32.83
Ref+Constrained
46.93
AloLab
85.75[80.00, 88.79]
GPT-4o
Naive
0.00
Reference
0.00
Constrained
not run
—
Ref+Constrained
not run
—
AloLab
95.22[94.75, 95.59]
  • Generalization probe, GSM8K only. Constrained strategies were not run.
  • Reference: the same markdown-fence wrapping as Gemma. The fallback parser recovers 95.7% task accuracy.
Table 2. The static strategies are single deterministic runs at temperature 0. AloLab is the mean of five independent runs, with a 95% bootstrap confidence interval (the white band inside its bar).

GPT-4o shows this is not only a small-model problem. Under the Reference prompt it, too, wraps its JSON in markdown fences and scores 0%. AloLab finds the same fix and reaches 95.22%, with a standard deviation of 0.55 points across five runs. §4.7

06The price of constraints

Constrained decoding attacks the problem from the other side. It restricts generation to a grammar, so the output is valid JSON by construction. The guarantee is real, and so is the bill: on GSM8K the constrained strategies run 3.6–8.2× slower than Naive, on every call, and still score below AloLab. They can also damage the content. Under Constrained decoding, 52.4% of Gemma’s outputs were exact duplicates. §4.2, §4.3

Inference latency, × Naive
AloLab · MATH
0.63–0.90×
AloLab · GSM8K
0.71–1.06×
AloLab · GPT-4o
0.69×
Constrained decoding · GSM8K
3.6–8.2×
1×4×6×8×
Ranges across models, from §4.3. The vertical rule marks Naive (1×). Constrained decoding spans 3.6× (Llama, Constrained) to 8.2× (Qwen, Ref+Constrained) and still trails AloLab on output accuracy for every model. AloLab runs at 0.71–1.06× Naive on GSM8K and 0.63–0.90× on MATH: its optimized prompts are shorter, which partly offsets their token overhead.

AloLab pays once, at optimization time. What ships is a prompt that runs at near-Naive latency, and on MATH slightly faster, since the optimized prompts are shorter. Plotted together, the trade-off has a clear frontier. §4.3

Figure 2. Output accuracy against inference latency.
Two scatter plots, GSM8K above and MATH below, with latency relative to Naive on the x axis and output accuracy on the y axis. AloLab points sit at the top left; Constrained points sit to the right, lower down.
Latency is relative to Naive, and the two panels use different x-axis scales. Diamonds mark GPT-4o, run on GSM8K only. Figure 2, arXiv:2605.02363.

07What the optimizer changed

AloLab does not apply a standard fix. It reads what a particular model gets wrong and writes the instruction that model needs. Two trajectories from the appendix show how different those instructions can be. Appendix A

Gemma · GSM8K · a habit

Under the Reference prompt, every reply arrives fenced. At epoch 2 the optimizer adds explicit rules against markdown and code blocks, and validation output accuracy jumps from 0% to about 80%. Nobody writing a prompt from scratch would think to forbid the fence without first watching this model use it.

Llama · MATH · a representation

The Reference prompt asks for answers in LaTeX. Inside a JSON string every LaTeX backslash must be escaped, and the model often doesn’t.

You are a math expert. Solve the problem step by step, then give the final answer.
Respond with a JSON object with keys “reasoning” (string) and “answer” (string).
Your final answer must be a mathematical expression. Use LaTeX notation if needed
(e.g. \frac{1}{2}, \sqrt{3}).

Rather than ask for more careful escaping, the optimizer removes LaTeX from the answer altogether:

ANSWER FORMAT RULES:
– For fractions: use “a/b” format (e.g. “3/4”)
– For square roots: use “sqrt(n)” format (e.g. “sqrt(5)”)
– For expressions: use plain text algebra (e.g. “x^2 + 2x + 1”)
json_valid47.4%→77.9%
output accuracy8.5%→39.0%

Two checks confirm where the gains come from. Hiding the model’s identity (name, family, size, quantization) from the optimizer changes mean output accuracy by only −0.7 points, with no significant effect: the signal is in the traces, not in knowing which model produced them. And the fixes track observed behaviour. Nothing about GSM8K predicts that a model will fence its JSON; you have to see it happen. §5

08The optimizer’s own model matters

The loop is only as good as the model reading the traces. Swap Claude Sonnet 4.5 for the much smaller Claude 3 Haiku, keep everything else fixed, and mean output accuracy for Llama on GSM8K falls from 84.15% to 61.0%. The spread between runs grows from under one point to 21.8. §4.8

Llama 3.1-8B · GSM8K · test output accuracy, %
Claude Sonnet 4.5mean 84.15 · std 0.6 pp
r1 83.78r2 84.76r3 84.61r4 84.23r5 83.40
Claude 3 Haikumean 61.00 · std 21.8 pp
r1 45.49r2 84.38r3 85.44r4 44.43r5 45.26
0255075100
Table 4. Same loop, same model and data, and only the meta-agent changes. Each dot is one run and the vertical rule is the mean. With Sonnet 4.5 all five runs land within about 1.4 points of each other. With Haiku two runs match Sonnet’s best and three stall around 45%.

The drop is bimodal, not uniform. Two Haiku runs find an effective prompt and match Sonnet; three fail or collapse. The loop works in principle. A weaker meta-agent just can’t find the fix reliably.

Figure 6. Meta-agent ablation, epoch by epoch.
Two panels for Llama 3.1-8B on GSM8K. Left, with Claude Sonnet 4.5 as meta-agent, all five runs rise to the same level. Right, with Claude 3 Haiku, runs split between high and low output accuracy.
Llama 3.1-8B on GSM8K, with Claude Sonnet 4.5 (left) and Claude 3 Haiku (right) as the meta-agent. Each line is one independent run. Figure 6, arXiv:2605.02363.

09How reliable the gains are

Every AloLab number is the mean of five independent runs, reported with a bootstrap confidence interval. We also tested each run against the Reference prompt on matched samples: 29 of 30 comparisons are significant at p < 0.05. §4.6

Paired McNemar tests · AloLab vs Referencep < 0.05 · 29not significant · 1
GSM8K
Llama 3.1-8B Instruct
Gemma 2-9B IT
Qwen 2.5-7B Instructrun 2: p = 0.286
MATH
Llama 3.1-8B Instruct
Gemma 2-9B IT
Qwen 2.5-7B Instruct
Five runs × three models × two datasets. The one miss, Qwen on GSM8K run 2, collapses at epoch 2. json_valid drops to near zero and never recovers, and the run ends at 74.3%, exactly the Reference score. That’s a convergence failure, not evidence of no effect.

Qwen is the least stable model. On MATH its interval spans 20.8–47.7%, because in two of five runs it settles on double-escaped LaTeX that the parser doesn’t recognise. Qwen produces that pattern under any prompt that allows LaTeX, Reference included; AloLab removes it in three runs out of five. §6

10Where it falls short

Output accuracy falls as problems get harder, and it falls the same way for all three models. That points to the difficulty of the task, not to a quirk of any one model. §4.5

AloLab output accuracy by difficulty
GSM8K · averaged across models
1–2 reasoning steps
91.2%
7+ reasoning steps
66.7%
MATH · by level
Level 1
67.1%
Level 5
17.9%
MATH · strongest and weakest subjects
Prealgebra
60.4%
Algebra
58.7%
Intermediate Algebra
25.2%
Precalculus
15.7%
§4.5. GSM8K difficulty is estimated by counting calculation annotations in the reference solution. MATH uses its own five levels and seven subjects. Only the extremes stated in the text are shown here. Figures 4 and 5 in the paper have every bucket, model and subject.

One failure survives optimization. Sometimes the JSON is valid and the reasoning field works toward the right answer, but the answer field holds a different value. A regex scan puts an upper bound of 15–21% on this among AloLab’s failures but over-counts; an independent LLM judge (Gemini 3 Flash) puts the true rate at 1.5–1.8%. It stands out under AloLab only because the simpler format errors are gone. §5

  • The optimizer needs a capable model. Reliable results depend on the meta-agent, and optimization is a one-time setup cost.
  • Both benchmarks are mathematical. Other tasks and other schemas are the next test.
  • MATH ran with a fixed 8,192-token context, which may cap what the models could reach.
  • Some ablations are narrow. The history-only and meta-agent ablations, and the GPT-4o probe, cover GSM8K only.

Under strict output contracts, the practical limits of small models are often not limits of reasoning. They are limits of structured communication, and that is the gap iterative, black-box prompt optimization is built to close. §7

—Citation

This page retells the paper for a wider audience. The paper on arXiv is the reference for every method detail, number and caveat.

Cite as

Galeone, C., Park, M., Ettorre, G., & Ligorio, D. (2026). When Correct Isn't Usable: Improving Structured Output Reliability in Small Language Models. arXiv:2605.02363.

BibTeX
@misc{galeone2026when,
  title         = {When Correct Isn't Usable: Improving Structured Output Reliability in Small Language Models},
  author        = {Galeone, Cosimo and Park, Minsu and Ettorre, Giuseppe and Ligorio, Daniele},
  year          = {2026},
  eprint        = {2605.02363},
  archivePrefix = {arXiv},
  primaryClass  = {cs.CL},
  url           = {https://arxiv.org/abs/2605.02363}
}

Photographs from Unsplash. Figures marked with a figure number are reproduced from the paper.