Short answer: make invoice extraction a bounded pipeline, not one heroic prompt. Measure tokens before the model call, chunk by invoice structure, retrieve only relevant passages, validate the JSON, and retry only operations that are safe to retry. This keeps a long supplier invoice from turnin...
Source: [Dev.to](https://dev.to/oswaldjohansson6946/text-to-json-extraction-explained-long-document-timeouts-token-limits-and-chunking-2i2g)