fix(ingestion): accept observed OCR text alias in partial mode

This commit is contained in:
amirhosein mazaheri
2026-10-14 14:01:51 +03:30
parent 77b8205db6
commit 2e8c179efc
4 changed files with 69 additions and 0 deletions
+11
View File
@@ -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):