Repository navigation
fix(azure_ai): preserve content, tables, and keyValuePairs in doc-intelligence /v1/ocr - #32018
Conversation
…elligence /v1/ocr Azure Document Intelligence analyzeResult.content, .tables, and .keyValuePairs were dropped when normalizing to the Mistral OCR schema. They are now passed through verbatim as top-level response fields, and the duplicated sync/async response parsing is consolidated into one pydantic-validated helper. Also adds the Azure DI features query param (list[str] or comma-separated string, e.g. features=keyValuePairs) which Azure requires for keyValuePairs extraction.
Greptile SummaryThis PR fixes the
Confidence Score: 5/5Safe to merge — the change is narrowly scoped to the Azure DI OCR transformation path, all logic is covered by new mock-based unit tests, and existing provider behavior is unchanged. The fix correctly preserves Azure-native fields that were always present in the API response but never forwarded. The refactor consolidates two near-identical code paths into a single well-tested helper without changing external behavior. Input validation for the new features param is strict and fully tested, including injection-style inputs and type mismatches. No auth, routing, or cross-provider logic is touched. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/llms/azure_ai/ocr/document_intelligence/transformation.py | Major refactor: adds Pydantic models for Azure DI response, consolidates sync/async response parsing into _transform_completed_response, adds features param support, and preserves content/tables/keyValuePairs in the OCR response. |
| litellm/llms/base_llm/ocr/transformation.py | Adds three new optional fields (content, tables, keyValuePairs) to the shared OCRResponse base class; for non-Azure providers they serialize as null with no effect. |
| tests/test_litellm/llms/azure_ai/test_azure_document_intelligence_ocr_transformation.py | New comprehensive unit tests covering native field passthrough, async path, missing-fields tolerance, error status handling, features param mapping, URL building, and invalid-input rejection — all using in-memory httpx.Response mocks, no network calls. |
| tests/ocr_tests/test_ocr_azure_document_intelligence.py | Existing test renamed and assertion updated from ["pages"] to ["pages", "features"] to reflect the newly advertised features param — correctly tracks the extended interface. |
Reviews (2): Last reviewed commit: "test(azure_ai): replace fastapi jsonable..." | Re-trigger Greptile
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 8735f49. Configure here.
mateo-berri
left a comment
There was a problem hiding this comment.
LGTM; thanks!
Relevant issues
Reported by a customer (Pylon #5296)
Linear ticket
Resolves LIT-4151
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
End-to-end against a live local proxy hitting the real Azure Document Intelligence API (resource
litellm-di-test-17f97.cognitiveservices.azure.com, real requests, no mocks). The before run is baselitellm_internal_stagingat 2633e8f; the after run is this PR's head d925bf9. Same venv, same port, same config both times. The test document is Azure's public layout sample PDF, which contains 2 tables and key-value pairsConfig (
qa_config.yaml):Proxy start (identical for both runs, after checking out the respective commit; editable install picks up whatever is checked out):
Before (base litellm_internal_staging, 2633e8f)
{ "has_content": false, "has_tables": false, "has_keyValuePairs": false, "content_populated": false, "tables_populated": false, "keyValuePairs_populated": false, "page0_keys": [ "dimensions", "images", "index", "markdown" ] }Azure's native
content,tables, andkeyValuePairsare dropped entirely; only the Mistral-schemapages[].markdownsurvivesAfter (this PR, d925bf9)
Same curl as above:
{ "has_content": true, "has_tables": true, "has_keyValuePairs": true, "content_populated": true, "tables_populated": true, "keyValuePairs_populated": false, "page0_keys": [ "dimensions", "images", "index", "markdown" ] }contentandtablesare now populated (2813 chars and 2 tables for this document) andpages[].markdownis unchanged.keyValuePairsserializes as null here because Azure only computes key-value pairs when thefeatures=keyValuePairsadd-on is requested; requesting it through the newfeaturesparam:{ "content_chars": 2813, "tables": 2, "keyValuePairs": 22, "page0_has_markdown": true }Type
🐛 Bug Fix
Changes
The
/v1/ocrendpoint normalizes Azure Document Intelligence (azure_ai/doc-intelligence/<model>) responses into the Mistral OCR schema and silently dropped Azure's nativeanalyzeResult.content(full-document text),analyzeResult.tables, andanalyzeResult.keyValuePairs. These are now passed through verbatim as top-levelcontent,tables, andkeyValuePairsfields on the OCR response, alongside the unchanged Mistral-schema fields. For other OCR providers the new fields simply serialize as nullAzure's analyze endpoint also takes a
featuresquery param, andfeatures=keyValuePairsis required for Azure to return key-value pairs at all.featuresis now a supported OCR param for Azure DI: it accepts a list of feature names (e.g.["keyValuePairs"]) or a comma-separated string, is validated against garbage input the same waypagesis, and is emitted comma-joined on the analyze URL (e.g.&features=keyValuePairs,languages), combining correctly withpagesWhile fixing both transform paths, the near-duplicate sync and async response parsing bodies were consolidated into a single helper that validates the Azure operation payload with pydantic models, so the fix lands once instead of twice
Regression tests in
tests/test_litellm/llms/azure_ai/test_azure_document_intelligence_ocr_transformation.pyfeed a realistic Azure analyzeResult payload through both transform paths and assert the native fields survive in the serialized response (viamodel_dump()), tolerate payloads without tables/keyValuePairs, and cover thefeaturesparam mapping, URL building, and invalid-input rejectionNote
Medium Risk
Adds optional fields to the shared OCR response contract and changes Azure analyze URL/query handling; behavior is additive and covered by tests, but proxy clients may depend on the slimmer response shape.
Overview
Fixes Azure Document Intelligence OCR responses dropping
analyzeResult.content,tables, andkeyValuePairswhen/v1/ocrnormalizes to the Mistral OCR shape. Those values are now copied to top-levelcontent,tables, andkeyValuePairsonOCRResponse(other providers leave themnull).Adds Azure’s
featuresanalyze query param (e.g.keyValuePairs) with the same style of validation aspages, URL emission inget_complete_url, andmap_ocr_paramsupdates so callers can request key-value extraction.Refactors sync/async Azure response handling into shared
_get_polling_target/_transform_completed_responsewith Pydantic models for the operation payload, so polling and parsing live in one place.Reviewed by Cursor Bugbot for commit 8735f49. Bugbot is set up for automated code reviews on this repo. Configure here.