You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Image description lane intermittently returns invalid JSON #511
The vision-LLM description lane of the image route (adapters/converters/image_ocr_description.py, default model google/gemini-2.5-flash via OpenRouter) intermittently returns output that does not parse as the expected JSON. The lane then fails and the image conversion has to be retried.
Expected
The lane uses structured output / a JSON schema, or a bounded repair-and-retry inside the lane. Callers should not need to retry whole conversions, and failures should be typed and retryable, with the raw output kept for diagnosis.
Repro
A batch of 35 raster images (e-Sbírka annex scans) through ImageOcrDescriptionConverter. Several attempts failed with invalid JSON from the description lane and succeeded on a retry. The total spent was ~$0.20 for 52 calls including retries, against ~$0.12 for the stored results.
Workaround in the downstream app
LegalIt esbirka/images.pyEngineRoutes.read() retries retryable lane errors up to N times. The lane checkpoints keep the OCR lane from being re-billed.
Notes
Related: the description prompt is English-only, so descriptions of non-English documents come out in English. Consider a configurable output language that follows the source language.
Root cause found: Gemini's RECITATION stop truncates the JSON (2026-10-22)
This is the same request the description lane sends (pinned baafc0ce prompt and JSON schema, google/gemini-2.5-flash via OpenRouter, max_tokens 4096). I sent it 10 times for one public scanned form.
Image:https://e-sbirka.gov.cz/sbr-cache/souborove-dokumenty/831501/NAHLED/STAHNI/x (JPEG, 1832×2586). It is a Czech form with long printed labels.
Result: 8 of the 10 calls failed, all in the same way:
message.content is a JSON object cut off mid-string, ending in the middle of a verbatim quote of the form's text, for example {"observations": "The image is a scan of a document, … The first label is \"Připojeny jednotlivé identifikace předmětů, pro které je požadováno uzavření dohody o poskytnutí náhrady z;
json.loads then raises "Unterminated string", and the lane reports "image description completion is not JSON".
The other 2 calls:finish_reason: "stop" and valid JSON.
Expected:
The lane checks finish_reason. An error/RECITATION stop becomes a typed, recognisable failure (with the raw output kept), not "not JSON".
The prompt discourages verbatim quoting of long visible text. OCR already carries the text, and quoting is what trips Google's recitation filter.
If a retry is the remedy, it is bounded.
How often: in our 35-image batch only text-dense forms hit this; plain seals and maps never did. For the form above the failure rate is 80%.
Activity
fazpu commentedon Oct 22, 2026
Root cause found: Gemini's RECITATION stop truncates the JSON (2026-10-22)
This is the same request the description lane sends (pinned
baafc0ceprompt and JSON schema,google/gemini-2.5-flashvia OpenRouter,max_tokens4096). I sent it 10 times for one public scanned form.https://e-sbirka.gov.cz/sbr-cache/souborove-dokumenty/831501/NAHLED/STAHNI/x(JPEG, 1832×2586). It is a Czech form with long printed labels.finish_reason: "error",native_finish_reason: "RECITATION", provider "Google AI Studio", usagecompletion_tokens: 0;message.contentis a JSON object cut off mid-string, ending in the middle of a verbatim quote of the form's text, for example{"observations": "The image is a scan of a document, … The first label is \"Připojeny jednotlivé identifikace předmětů, pro které je požadováno uzavření dohody o poskytnutí náhrady z;json.loadsthen raises "Unterminated string", and the lane reports "image description completion is not JSON".finish_reason: "stop"and valid JSON.Expected:
finish_reason. Anerror/RECITATIONstop becomes a typed, recognisable failure (with the raw output kept), not "not JSON".How often: in our 35-image batch only text-dense forms hit this; plain seals and maps never did. For the form above the failure rate is 80%.