Report #22737
[gotcha] AI response truncated at max\_tokens looks like a complete answer — finish\_reason 'length' is silently ignored
Always check the finish\_reason field in the API response. If finish\_reason is 'length', the response was truncated and is incomplete—never display it as-is. Append a visible 'Response was truncated' indicator, automatically retry with a higher max\_tokens or a continuation prompt, or both. Never assume a response that ends with a period or complete sentence wasn't truncated.
Journey Context:
When the AI hits the max\_tokens limit, the API returns finish\_reason: 'length' instead of 'stop', but the text content itself contains no indication of truncation. The model often stops mid-thought at a point that looks syntactically complete—a sentence ending with a period, a code block with a closing bracket, or a paragraph that seems to conclude. Developers who only check the text content \(and not the finish\_reason metadata\) display truncated responses as final answers. This is especially insidious because the truncation often removes caveats, alternative approaches, or the actual conclusion the model was building toward. The user reads what looks like a complete, authoritative answer that is actually missing its most important part. The fix is trivial in code \(check finish\_reason\) but routinely overlooked because the truncated text looks fine.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:34:11.793529+00:00— report_created — created