fix(ingestion): accept observed OCR text alias in partial mode
This commit is contained in:
@@ -159,7 +159,16 @@ class OpenRouterVision:
|
||||
raw_dict = json.loads(raw_text)
|
||||
valid_types = {"paragraph", "heading", "table", "question", "answer", "visual_group", "caption"}
|
||||
type_map = {"text": "paragraph", "body": "paragraph", "header": "heading", "title": "heading", "list": "paragraph"}
|
||||
text_alias_used = False
|
||||
for i, b in enumerate(raw_dict.get("blocks", [])):
|
||||
# Observed provider field alias, only in explicit partial admission.
|
||||
# Transfer verbatim text; conflicting fields must never be guessed.
|
||||
if allow_partial_extraction(processing_profile) and "text_content" in b:
|
||||
alias = b["text_content"]
|
||||
if not isinstance(alias, str) or ("text" in b and b["text"] != alias):
|
||||
raise ExtractionError("Conflicting vision text fields")
|
||||
b["text"] = b.pop("text_content")
|
||||
text_alias_used = True
|
||||
if b.get("block_type") not in valid_types:
|
||||
b["block_type"] = type_map.get(str(b.get("block_type", "")).lower(), "paragraph")
|
||||
if b.get("method") not in ("ocr", "vision"):
|
||||
@@ -190,6 +199,8 @@ class OpenRouterVision:
|
||||
}))
|
||||
# Recognition diagnostics belong to the exact review candidate.
|
||||
warnings = transcript.warnings + (() if transcript.complete else ("Vision recognition incomplete; completeness review required",))
|
||||
if text_alias_used:
|
||||
warnings += ("Provider text_content field mapped verbatim to text",)
|
||||
if warnings:
|
||||
blocks = [b.model_copy(update={"warnings": b.warnings + warnings}) for b in blocks]
|
||||
if allow_partial_extraction(processing_profile):
|
||||
|
||||
@@ -27,6 +27,7 @@ class ExtractionError(ValueError):
|
||||
# Only fixed categories enter logs; never exception/provider payload text.
|
||||
self.reason_code = {
|
||||
"Invalid vision transcription response": "invalid_vision_schema",
|
||||
"Conflicting vision text fields": "conflicting_vision_text_fields",
|
||||
"Vision reports unreadable source regions": "unreadable_vision_regions",
|
||||
"Vision evidence identity, location or readability mismatch": "invalid_vision_evidence",
|
||||
"Vision transcription incomplete or blocked": "incomplete_or_blocked_vision",
|
||||
|
||||
Reference in New Issue
Block a user