Skip to content

feat(doc-intel): expose models, features, query fields, and structured output - #1913

Merged
Adam Fourney (afourney) merged 12 commits into
microsoft:mainfrom
chienyuanchang:chienyuanchang/di_convertor_update
Oct 22, 2026
Merged

Adam Fourney (afourney) merged 12 commits into
microsoft:mainfrom
chienyuanchang:chienyuanchang/di_convertor_update

Conversation

@chienyuanchang

@chienyuanchang Chien Yuan Chang (chienyuanchang) commented May 26, 2026 •

Copy link
Copy Markdown
Member

Summary

  • expose Document Intelligence model selection with docintel_model_id
  • expose analysis add-ons with docintel_features; no analysis add-ons are enabled by default, and callers explicitly opt in to the features they need
  • expose queryFields with docintel_query_fields; when query fields are provided, MarkItDown adds the required queryFields feature
  • serialize structured fields from prebuilt and custom models as YAML front matter
  • add matching CLI flags for model, features, and query fields
  • retain the SDK-default API version behavior from fix(doc-intel): default api_version to None in DocumentIntelligenceConverter #2267 while adding MarkItDown user-agent telemetry
  • document API-key, AZURE_API_KEY, and DefaultAzureCredential authentication

Consolidated work

Usage

from azure.ai.documentintelligence.models import DocumentAnalysisFeature
from markitdown import MarkItDown

md = MarkItDown(
    docintel_endpoint="<document_intelligence_endpoint>",
    docintel_model_id="prebuilt-layout",
    docintel_features=[
        DocumentAnalysisFeature.OCR_HIGH_RESOLUTION,
        DocumentAnalysisFeature.STYLE_FONT,
    ],
    docintel_query_fields=["Title", "Author"],
)
result = md.convert("document.pdf")
print(result.markdown)

Omit docintel_features or pass docintel_features=[] to request no analysis add-ons. Paid features such as formulas, ocrHighResolution, and styleFont must be enabled explicitly. Office inputs continue to omit OCR-only add-ons. When query fields are provided, MarkItDown adds the required queryFields feature without mutating the caller's feature list.

Validation

  • GITHUB_ACTIONS=1 python -m pytest packages/markitdown/tests -q — 1080 passed, 57 skipped
  • focused Document Intelligence and CLI tests — 54 passed
  • Black 23.7.0 — 5 changed Python files unchanged
  • git diff --check
  • live Entra-authenticated Document Intelligence calls:
    • prebuilt-layout succeeded with no add-ons and with explicitly configured add-ons, including ocrHighResolution
    • prebuilt-read succeeded with no add-ons and returned its expected flatter text-oriented Markdown
    • prebuilt-receipt succeeded with no add-ons and produced structured YAML front matter
    • the queryFields request path was accepted with valid identifiers, but the selected repository samples returned no query-field documents; positive field serialization remains covered by unit tests

Credits

@chienyuanchang
Chien Yuan Chang (chienyuanchang) marked this pull request as ready for review May 26, 2026 17:01
Preserve the SDK-default API version behavior from microsoft#2267 while retaining Document Intelligence user-agent telemetry.

Co-authored-by: Copilot <[email protected]>
Add configurable analysis features, CLI and README coverage, and API-key authentication guidance while integrating queryFields and structured model output.

Co-authored-by: Tai An <[email protected]>

Co-authored-by: hshgogogo <[email protected]>

Co-authored-by: Copilot <[email protected]>
@chienyuanchang Chien Yuan Chang (chienyuanchang) changed the title feat: Expand Document Intelligence converter — custom models, queryFields, structured field front matter feat(doc-intel): expose models, features, query fields, and structured output Oct 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Structured output can produce invalid or incorrectly typed YAML and lose or misattribute fields from multiple documents.

2 open issues
What changed in this PR

This PR expands MarkItDown’s Azure Document Intelligence integration with configurable analysis options and structured output while preserving existing defaults.

Changes:

  • Exposes model selection, analysis features, and query fields through Python and CLI options.
  • Adds YAML front matter for extracted fields and MarkItDown user-agent telemetry.
  • Documents authentication options and adds converter and CLI tests.
File Description
README.md Documents authentication, configuration, and structured output.
packages/​markitdown/​tests/​test_docintel_converter.py Tests configuration, request forwarding, telemetry, and front matter.
packages/​markitdown/​tests/​test_cli_misc.py Tests forwarding Document Intelligence CLI options.
packages/​markitdown/​src/​markitdown/​converters/​_doc_intel_converter.py Implements configurable analysis and structured-field serialization.
packages/​markitdown/​src/​markitdown/​_markitdown.py Forwards public configuration to the converter.
packages/​markitdown/​src/​markitdown/​__main__.py Adds and parses Document Intelligence CLI flags.

Review effort: Balanced

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@afourney

Copy link
Copy Markdown
Member

This comment was auto-generated by GPT-6 Astra and posted at the repository maintainer’s request.

Rechecked commit fd3b526c641b11d9e24dd5040ad21fd58a67ebca. The YAML quoting change resolves the examples from the earlier review: all 18 string key/value round-trip checks and 50 focused Document Intelligence and CLI tests passed.

Two P2 findings remain:

  1. Preserve document boundaries when serializing structured fields. _fields_to_front_matter() merges every document into one mapping. Later documents overwrite matching fields but retain unmatched fields from earlier documents. With two SDK AnalyzedDocument objects, I reproduced Vendor B’s name and invoice ID paired with Vendor A’s invoice total. This produces a record that never existed and discards earlier documents’ fields. Serialize each document’s fields separately and add coverage for overlapping and missing fields across documents. Code

  2. Handle selection-group values before falling back to raw content. _field_value() does not handle value_selection_group. An SDK DocumentField(type="selectionGroup", value_selection_group=["Email"]) returns None and disappears from the front matter when content is absent. When raw content is present, the selected values are still lost in favor of that text. Preserve the selected-value list and add regression coverage. Code

I recommend addressing these before merging. Validation used local SDK objects and mocked service calls; the full suite and live Azure calls were not run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Structured fields containing control characters can produce invalid YAML front matter that downstream parsers reject.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Escape control characters in quoted YAML strings

packages/​markitdown/​src/​markitdown/​converters/​_doc_intel_converter.py:223

The quoted-string escaping leaves control characters such as form feed (U+000C) and backspace (U+0008) unchanged. For example, a structured field containing page one\fpage two produces a literal form feed inside the quoted scalar. YAML forbids that character even inside quotes, so downstream consumers cannot parse the front matter. Escape the remaining control characters and add a regression case for a field containing a form feed.

2 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Scientific-notation floats can lose their numeric type when the generated front matter is parsed by YAML 1.1 readers.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Preserve numeric type for scientific-notation floats

packages/​markitdown/​src/​markitdown/​converters/​_doc_intel_converter.py:206

Scientific-notation floats lose their numeric type with YAML 1.1 readers such as yaml.safe_load, which the new round-trip tests use. For example, value_number=1e-7 is emitted as 1e-07 and loads as a string rather than a float; 1e20 has the same problem. Include a decimal point in exponential float mantissas (for example, 1.0e-07) and add numeric round-trip regressions for small and large values.

Review effort: Balanced

@afourney
Adam Fourney (afourney) merged commit 7482c09 into microsoft:main Oct 22, 2026
23 checks passed
Ahmet (ANO3457) pushed a commit to ANO3457/markitdown that referenced this pull request Oct 24, 2026
San-Hsien (SanHsien) pushed a commit to SanHsien/markitdown that referenced this pull request Oct 25, 2026
本 repo 已停用 issues,接續開發報告依規定寫在本 commit 訊息。

# 接續開發報告 2026-10-25

## 一、線索與處理
- open/draft PR:無。PR #1 已關閉未合併,內容已 squash 進 main(bebd625),
  head 分支 ci/job-names-20261024 已不在遠端。
- 非預設分支:只有 claude/gifted-dirac-r9vpm0(本 session 工作分支,內容已 fast-forward 進 main)。
- open issue:無(issues 已停用)。
- main 紅燈 Dependency freshness:ruff 0.17.2。對 E9+F gate 全綠,記入
  .github/dependency-deferrals.json(deferredLatest),未調高下限 → 已轉綠。
- main 紅燈 Upstream check:20 commit/153 PR/40 issue 未審 → 第三輪審查完成,已轉綠。
- HANDOFF.md/TODO.md:不存在。程式碼 TODO/FIXME 7 處皆為上游產品碼,不動。
- REVIEW.md:R-01~R-10 已修,無未修項。
- 2026-09-30 待辦 microsoft#2506:觸發條件成立(上游整併測試依賴它),已採用(4a377f9)。

## 二、做了什麼(bebd625..本 commit)
- 上游 commit:cherry-pick -x 本輪 20 筆中 19 筆(9a15f66..e211f83),microsoft#2731 部分採用(3e440d7),
  補採 microsoft#2506(4a377f9)。
- 例外移植上游 OPEN PR,皆先重現缺陷、附 PR 測試:
  - microsoft#2674(1029094):短 UTF-8 文字被誤判 UTF-16 亂碼。
  - microsoft#2742(9947ed1):UTF-8 BOM 殘留。
  - microsoft#2738(38a2ae6):Outlook MSG 尾端 NUL。
  - microsoft#2620(0d1140c):大寫副檔名音訊不轉譯。
- 依賴(c561006):
  - requirements 跟隨上游 magika/mammoth/certifi,補列 ocr 漏的 PyMuPDF、Pillow。
  - dependabot 補 ocr 與 sample-plugin 目錄。
  - ruff 延後。
- 文件(8f1db57、3382745、b618bc9、本 commit):
  - microsoft#1913 英文段落併入 README.en.md。
  - 繁中 README text_content → markdown。
  - DECISIONS/UPSTREAM/baseline 推進水位。
- CI(d4c2b7a):移除 microsoft#2586 帶進 tests.yml 的 Linux 專用 apt-get 步驟(R-09)。
- 驗證:
  - 每批推送前由全新審查員審 diff 並等 Windows CI 完成(一次 NO-SHIP,修正後重審 ship)。
  - 維護 gate 與 Windows CI py3.10–3.14 全綠。
  - 產品測試(Linux 雲端)1312 passed/12 skipped/2 failed,2 個失敗皆因沙箱無對外網路。

## 三、上游結論
- 水位:commit 7482c09、PR microsoft#2765、issue microsoft#2762。
- commit:採用 18、部分採用 1(microsoft#2731 ARM/pre-commit CI 不適用),microsoft#2733 版本 bump 不適用。
- PR:
  - MERGED 12,例外移植 4。
  - 其餘 OPEN 不 fork-ahead,等上游合併。
  - 無 merge ref 12 筆多為重複,不採。
- issue:已修 2(microsoft#2646、microsoft#2719),16 筆對應 OPEN PR,其餘為不適用、觸發條件或垃圾。
- 逐筆見 docs/DECISIONS.md 2026-10-25。

## 四、刻意不做(理由/觸發條件)
- microsoft#2756 ZIP 檔名:會把 Big5「臺灣報告.pdf」解成亂碼(誤判為 shift_jis_2004)。
  觸發:上游合併時先補 cp950 測試,或改為優先 metadata_encoding/locale。
- microsoft#2621/microsoft#2622 SSRF 政策:牽動 MCP/URI 擷取。
  觸發:上游合併,或本 fork 對外提供 MCP HTTP 服務。
- microsoft#2679/microsoft#2723 cp1252 偵測:可能影響 CJK 舊碼頁。觸發:上游合併後跑 CJK charset 測試。
- microsoft#2407 youtube-transcript-api ~=1.2.3:維持本 fork >=1.0.0+freshness-hold。
- microsoft#2740 Python 3.15:上游 CI 加 3.15 時同步 ci.yml。

## 五、需要維護者決定
1. 雲端 session 對 microsoft/markitdown 無 API 權限(只能匿名 git 讀取)。
   本輪 PR/issue 清單取自本 fork Upstream check log,狀態以 refs/pull/*/merge 判斷。
2. 產品程式變動只在 Linux 跑過;ci.yml 只跑維護 gate。請在 Windows 11 本機跑
   pwsh -NoProfile -File tools\test_product.ps1 -AllPackages。
3. 「不 fork-ahead」政策的 4 筆例外移植;若不同意可 revert 1029094、9947ed1、38a2ae6、0d1140c。

STATUS: NEEDS-MAINTAINER Windows 11 本機跑 test_product.ps1 -AllPackages;確認是否接受 4 筆上游 open PR 例外移植

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014CWBckUdMZcCAsc15iaJtm
San-Hsien (SanHsien) pushed a commit to SanHsien/markitdown that referenced this pull request Oct 25, 2026
本 repo 已停用 issues,接續開發報告依規定寫在本 commit 訊息。

# 接續開發報告 2026-10-25

## 一、線索與處理
- open/draft PR:無。PR #1 已關閉未合併,內容已 squash 進 main(bebd625),
  head 分支 ci/job-names-20261024 已不在遠端。
- 非預設分支:只有 claude/gifted-dirac-r9vpm0(本 session 工作分支,內容已 fast-forward 進 main)。
- open issue:無(issues 已停用)。
- main 紅燈 Dependency freshness:ruff 0.17.2。對 E9+F gate 全綠,記入
  .github/dependency-deferrals.json(deferredLatest),未調高下限 → 已轉綠。
- main 紅燈 Upstream check:20 commit/153 PR/40 issue 未審 → 第三輪審查完成,已轉綠。
- HANDOFF.md/TODO.md:不存在。程式碼 TODO/FIXME 7 處皆為上游產品碼,不動。
- REVIEW.md:R-01~R-10 已修,無未修項。
- 2026-09-30 待辦 microsoft#2506:觸發條件成立(上游整併測試依賴它),已採用(4a377f9)。

## 二、做了什麼(bebd625..本 commit)
- 上游 commit:cherry-pick -x 本輪 20 筆中 19 筆(9a15f66..e211f83),microsoft#2731 部分採用(3e440d7),
  補採 microsoft#2506(4a377f9)。
- 例外移植上游 OPEN PR,皆先重現缺陷、附 PR 測試:
  - microsoft#2674(1029094):短 UTF-8 文字被誤判 UTF-16 亂碼。
  - microsoft#2742(9947ed1):UTF-8 BOM 殘留。
  - microsoft#2738(38a2ae6):Outlook MSG 尾端 NUL。
  - microsoft#2620(0d1140c):大寫副檔名音訊不轉譯。
- 依賴(c561006):
  - requirements 跟隨上游 magika/mammoth/certifi,補列 ocr 漏的 PyMuPDF、Pillow。
  - dependabot 補 ocr 與 sample-plugin 目錄。
  - ruff 延後。
- 文件(8f1db57、3382745、b618bc9、本 commit):
  - microsoft#1913 英文段落併入 README.en.md。
  - 繁中 README text_content → markdown。
  - DECISIONS/UPSTREAM/baseline 推進水位。
- CI(d4c2b7a):移除 microsoft#2586 帶進 tests.yml 的 Linux 專用 apt-get 步驟(R-09)。
- 驗證:
  - 每批推送前由全新審查員審 diff 並等 Windows CI 完成(一次 NO-SHIP,修正後重審 ship)。
  - 維護 gate 與 Windows CI py3.10–3.14 全綠。
  - 產品測試(Linux 雲端)1312 passed/12 skipped/2 failed,2 個失敗皆因沙箱無對外網路。

## 三、上游結論
- 水位:commit 7482c09、PR microsoft#2765、issue microsoft#2762。
- commit:採用 18、部分採用 1(microsoft#2731 ARM/pre-commit CI 不適用),microsoft#2733 版本 bump 不適用。
- PR:
  - MERGED 12,例外移植 4。
  - 其餘 OPEN 不 fork-ahead,等上游合併。
  - 無 merge ref 12 筆多為重複,不採。
- issue:已修 2(microsoft#2646、microsoft#2719),16 筆對應 OPEN PR,其餘為不適用、觸發條件或垃圾。
- 逐筆見 docs/DECISIONS.md 2026-10-25。

## 四、刻意不做(理由/觸發條件)
- microsoft#2756 ZIP 檔名:會把 Big5「臺灣報告.pdf」解成亂碼(誤判為 shift_jis_2004)。
  觸發:上游合併時先補 cp950 測試,或改為優先 metadata_encoding/locale。
- microsoft#2621/microsoft#2622 SSRF 政策:牽動 MCP/URI 擷取。
  觸發:上游合併,或本 fork 對外提供 MCP HTTP 服務。
- microsoft#2679/microsoft#2723 cp1252 偵測:可能影響 CJK 舊碼頁。觸發:上游合併後跑 CJK charset 測試。
- microsoft#2407 youtube-transcript-api ~=1.2.3:維持本 fork >=1.0.0+freshness-hold。
- microsoft#2740 Python 3.15:上游 CI 加 3.15 時同步 ci.yml。

## 五、需要維護者決定
1. 雲端 session 對 microsoft/markitdown 無 API 權限(只能匿名 git 讀取)。
   本輪 PR/issue 清單取自本 fork Upstream check log,狀態以 refs/pull/*/merge 判斷。
2. 產品程式變動只在 Linux 跑過;ci.yml 只跑維護 gate。請在 Windows 11 本機跑
   pwsh -NoProfile -File tools\test_product.ps1 -AllPackages。
3. 「不 fork-ahead」政策的 4 筆例外移植;若不同意可 revert 1029094、9947ed1、38a2ae6、0d1140c。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014CWBckUdMZcCAsc15iaJtm
STATUS: NEEDS-MAINTAINER Windows 11 本機跑 test_product.ps1 -AllPackages;確認是否接受 4 筆上游 open PR 例外移植
San-Hsien (SanHsien) added a commit to SanHsien/markitdown that referenced this pull request Oct 26, 2026
…R watermark

Ten new upstream PRs, none adopted. Four are real fixes (xlsx error
values, ipynb string source, RSS 1.0, data URI fragment) whose defects
reproduce on this fork but are outside the Windows/CJK exception class;
six are noise or re-submissions of already-adopted microsoft#1913. Reasons and
revisit triggers are in docs/DECISIONS.md. PR watermark 2765 -> 2775.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants