← Back to Pull requests

fix(image): validate LightOnOCR-3 prompt types #6264

Open
unknown opened this pull request with 408 lines diff across 5 files
View on GitHub
unknown unknown commented on Dec 01, 2026 11:00 UTC
Author

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 ` prompt must 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 its invalid_model_request reason. 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 backend ValueError that 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 on 9c013a11. The full validation file recorded 296 passed, 5 failed and 6 skipped on the fix. The same five embedding cases failed on base with missing tiktoken. The six PDF cases skipped because pypdfium2 was 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 from 9c013a11 the 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 of ad8acdb7. With lighton_ocr3.py from 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 that prompt: false records no model error event and that a backend ValueError returns 500 and records exactly one. On Windows Python 3.10.20 and 3.14.6 the no-event assertion failed on d4d60d6b and passes with the change. On Ubuntu 24.04 at feee0893, 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 from d4d60d6b` 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

Diff: 408 lines (+306 / -102) across 5 files Reviewer: Jackmeson1 Review duration: 369m
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
0.50
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 49.8% (MEDIUM) · Higher = larger blast radius
49.8%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 26.6% · Safe to merge
26.6%