Arrays and Counts: Why Models Return Seven of Ten Items
You ask for every line item on the invoice. There are ten. You get seven, the JSON validates, and nothing anywhere reports a problem. This is the single most reported structured-output bug and at least half the time the model is not the cause. Four causes, wildly different fixes Cause Description Truncation finish_reason == 'length'. The list was cut off mid-flight. Your max_tokens, not the model's recall. Chunk boundary Items 8-10 were on a page you did not send. Check what text actually reached the model. Dropped constraint You set minItems and the provider ignored it, so nothing enforced anything. Genuine omission Everything was present and the model stopped early. The only one that is actually about the model. Diagnose in that order, because the first three are cheap to rule out and the fourth is the expensive one to work on. Log finish_reason , usage.completion_tokens and the length of the text you sent on every extraction call and the first two answer themselves. The constraint you thought you set minItems and maxItems sit outside the documented supported keyword set for hosted strict modes. Depending on the stack, sending them either gets you a 400 naming the keyword — fine, you learn immediately — or a 200 where the keyword was quietly discarded. The second case is the trap, because your schema is now a comment. You believe a floor is enforced, the API returned success, and the array is short. Nothing in any log says the constraint was never applied. Find out which of the two your endpoint does before you rely on it — and either way, put “every item, do not summarise or skip” in the array’s description , since that reaches the model whether or not the keyword survives. Why counting is hard for a decoder There is no counter. Each token is produced from the context, and the context contains the items already emitted — so “have I got them all” is not a lookup, it is a judgement the model re-makes at every array element from what it can see. Two structural conse