fix(image): validate LightOnOCR-3 prompt types #6264
All Vouch review confidence checks passed
Residual risk 0.27 = Change Risk (0.50) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 408 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.360
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #6264"
general
weight: 0.35
Jackmeson1
Fixes #6263
What happens
LightOnOCR-3 accepts a string or JSON null as its multipart
kwargs.prompt. Other JSON types now receive HTTP 400 with the detail `promptmust be a string or null.| Request | Before | After |
| --- | --- | --- |
| prompt: 5
| 500 from.strip()| 400 |prompt: false|
,[]or{}| 200 with default OCR | 400 || Omitted, null or blank prompt | 200 with default OCR | 200 with default OCR |
| Valid prompt with a generation failure | 500 | 500 |
Cause
The formatter applied (prompt or "").strip()
before checking the type. That called a string method on nonzero numbers and converted false-valued inputs to an empty string.Change
Validate the type in the formatter shared by the Transformers, vLLM and SGLang adapters. The OCR route now handles InvalidModelRequestError
before logging or reporting a model failure, so invalid prompts return the same 400 detail without adding a model error event; the rejection keeps itsinvalid_model_requestreason. The multipart parser and other OCR families keep their existing contracts.Tests
The regression posts a PNG through /v1/images/ocr
, the decorated model actor and the Transformers adapter. It checks image-only, custom and grounding inputs, rejection before generation, and a backendValueErrorthat returns 500.Windows Python 3.10.20 and 3.14.6 with Transformers 5.17.0 produced identical results on c9a12a0f
(before the regression was shortened). All 18 submitted PNG cases passed and all 18 failed at the HTTP 400 assertion on9c013a11. The full validation file recorded 296 passed, 5 failed and 6 skipped on the fix. The same five embedding cases failed on base with missingtiktoken. The six PDF cases skipped becausepypdfium2was unavailable.On Ubuntu 24.04 at 1ff7da5c
(the shortened regression), the changed test file passed on Python 3.12 with Transformers 5.24.1 and 4.57.6 and on Python 3.10 (284 each), as did the consumer tests, pre-commit on the changed files and mypy over the repository; with production code from9c013a11the new cases fail at the HTTP 400 assertion.I then rebased onto ad8acdb7
, where main had added tests to the same file. On Windows Python 3.10.20 and 3.14.6 the rebased file had 285 passed and 5 failed; the same 5 token-ID tests also fail on an export ofad8acdb7. Withlighton_ocr3.pyfrom before this change, the new case is the only additional failure.The follow-up commit feee0893
adds that route handling. The multipart regression now also checks thatprompt: falserecords no model error event and that a backendValueErrorreturns 500 and records exactly one. On Windows Python 3.10.20 and 3.14.6 the no-event assertion failed ond4d60d6band passes with the change. On Ubuntu 24.04 atfeee0893, the changed test file passed on Python 3.12 with Transformers 5.24.1 and 4.57.6 and on Python 3.10 (290 each); with production code fromd4d60d6b` it fails. Pre-commit and mypy over the repository passed, and the consumer suite had only failures that also occur on the base.AI disclosure: this was prepared with AI assistance (Claude Code with Claude Opus 5.5, and OpenAI Codex with GPT-6.2).
🤖 Generated with Claude Code