From 3bd5f8173330f12792dddccb994d99d6427ec36a Mon Sep 17 00:00:00 2001 From: etienne-alby <68907958+etienne-alby@users.noreply.github.com> Date: Thu, 22 Oct 2026 12:29:45 +0200 Subject: [PATCH 1/3] Nutrient DWS: ask for inline formatting in the hosted Markdown --- .../inference/providers/parse/nutrient_dws.py | 7 ++++-- .../parse/test_nutrient_dws_errors.py | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/parse_bench/inference/providers/parse/nutrient_dws.py b/src/parse_bench/inference/providers/parse/nutrient_dws.py index 7d960768..7db616d0 100644 --- a/src/parse_bench/inference/providers/parse/nutrient_dws.py +++ b/src/parse_bench/inference/providers/parse/nutrient_dws.py @@ -1,7 +1,7 @@ """Provider for Nutrient DWS Data Extraction PARSE. Only the options in the published contract are sent (``format``/``formats``, -``includeWords``). Unknown options are accepted and ignored rather than rejected, +``includeWords``, ``enableInlineFormatting``). Unknown options are accepted and ignored rather than rejected, and some combinations degrade the markdown silently. Credits are charged per page. ``usage.data_extraction_credits.cost`` is recorded @@ -171,11 +171,14 @@ def _instructions(self) -> str: # `enableSemanticBlockFormatting` / `includeHeadersAndFooters` are not in # the contract and that combination strips chart tables and interleaves # running headers into the body. `includeWords` defaults to false and - # carries the style flags the formatting rules score. + # carries the style flags the formatting rules score. `enableInlineFormatting` + # defaults to false and writes those styles into `output.markdown`, the + # body when `body_source` is "hosted"; the graph body styles itself. if self._spatial: output: dict[str, Any] = { "formats": ["markdown", "spatial"], "includeWords": True, + "enableInlineFormatting": True, } else: output = {"format": "markdown"} diff --git a/tests/parse_bench/inference/providers/parse/test_nutrient_dws_errors.py b/tests/parse_bench/inference/providers/parse/test_nutrient_dws_errors.py index 2f47a758..48a25b0f 100644 --- a/tests/parse_bench/inference/providers/parse/test_nutrient_dws_errors.py +++ b/tests/parse_bench/inference/providers/parse/test_nutrient_dws_errors.py @@ -1,5 +1,6 @@ from __future__ import annotations +import json import os import unittest from pathlib import Path @@ -100,3 +101,26 @@ def test_rate_is_overridable(self) -> None: if __name__ == "__main__": unittest.main() + + +class TestInstructions(unittest.TestCase): + """The options each mode sends.""" + + def test_spatial_modes_ask_for_words_and_inline_formatting(self) -> None: + for mode in ("structure", "understand", "agentic"): + provider = NutrientDwsProvider("nutrient_dws", {"mode": mode, "api_key": "test"}) + self.assertEqual( + json.loads(provider._instructions()), + { + "mode": mode, + "output": { + "formats": ["markdown", "spatial"], + "includeWords": True, + "enableInlineFormatting": True, + }, + }, + ) + + def test_text_mode_sends_only_the_markdown_format(self) -> None: + provider = NutrientDwsProvider("nutrient_dws", {"mode": "text", "api_key": "test"}) + self.assertEqual(json.loads(provider._instructions()), {"mode": "text", "output": {"format": "markdown"}}) From 45c839deb9d0893fc39c00b2842507bde56d9055 Mon Sep 17 00:00:00 2001 From: etienne-alby <68907958+etienne-alby@users.noreply.github.com> Date: Sun, 25 Oct 2026 20:42:49 +0100 Subject: [PATCH 2/3] Nutrient DWS: describe the Markdown switches the provider leaves to DWS's defaults All five Markdown switches are in the public contract now; hosted pins the documented defaults for the four the provider doesn't send. Move the instruction tests above the main guard. --- .../inference/providers/parse/nutrient_dws.py | 20 +++++++++---------- .../parse/test_nutrient_dws_errors.py | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/parse_bench/inference/providers/parse/nutrient_dws.py b/src/parse_bench/inference/providers/parse/nutrient_dws.py index 7db616d0..e4d48a4d 100644 --- a/src/parse_bench/inference/providers/parse/nutrient_dws.py +++ b/src/parse_bench/inference/providers/parse/nutrient_dws.py @@ -1,8 +1,8 @@ """Provider for Nutrient DWS Data Extraction PARSE. -Only the options in the published contract are sent (``format``/``formats``, -``includeWords``, ``enableInlineFormatting``). Unknown options are accepted and ignored rather than rejected, -and some combinations degrade the markdown silently. +Only options from the published contract are sent (``format``/``formats``, +``includeWords``, ``enableInlineFormatting``). Unknown options are accepted and +ignored rather than rejected. Credits are charged per page. ``usage.data_extraction_credits.cost`` is recorded on ``raw_output`` as ``credits_used``; its sibling ``remainingCredits`` is not a @@ -167,13 +167,13 @@ def credit_rate_usd(self) -> float | None: def _instructions(self) -> str: # `text` mode takes the singular `format`; the spatial modes take # `formats` and additionally return `output.elements`. - # Contract options only. `useHtmlTables` / - # `enableSemanticBlockFormatting` / `includeHeadersAndFooters` are not in - # the contract and that combination strips chart tables and interleaves - # running headers into the body. `includeWords` defaults to false and - # carries the style flags the formatting rules score. `enableInlineFormatting` - # defaults to false and writes those styles into `output.markdown`, the - # body when `body_source` is "hosted"; the graph body styles itself. + # `includeWords` defaults to false and carries the style flags the + # formatting rules score. `enableInlineFormatting` defaults to false and + # writes those styles into `output.markdown` (the body when `body_source` + # is "hosted"); the graph body styles itself from the word flags. The + # other Markdown switches (`useHtmlTables`, `enableSemanticBlockFormatting`, + # `includeHeadersAndFooters`, `extractWordsFromPictures`) keep the defaults + # DWS documents and pins for every Markdown request, so they aren't sent. if self._spatial: output: dict[str, Any] = { "formats": ["markdown", "spatial"], diff --git a/tests/parse_bench/inference/providers/parse/test_nutrient_dws_errors.py b/tests/parse_bench/inference/providers/parse/test_nutrient_dws_errors.py index 48a25b0f..52887a61 100644 --- a/tests/parse_bench/inference/providers/parse/test_nutrient_dws_errors.py +++ b/tests/parse_bench/inference/providers/parse/test_nutrient_dws_errors.py @@ -99,10 +99,6 @@ def test_rate_is_overridable(self) -> None: self.assertEqual(self._provider(credit_rate_usd=0.0012).credit_rate_usd, 0.0012) -if __name__ == "__main__": - unittest.main() - - class TestInstructions(unittest.TestCase): """The options each mode sends.""" @@ -124,3 +120,7 @@ def test_spatial_modes_ask_for_words_and_inline_formatting(self) -> None: def test_text_mode_sends_only_the_markdown_format(self) -> None: provider = NutrientDwsProvider("nutrient_dws", {"mode": "text", "api_key": "test"}) self.assertEqual(json.loads(provider._instructions()), {"mode": "text", "output": {"format": "markdown"}}) + + +if __name__ == "__main__": + unittest.main() From 2969e128e395f2fb86cd22a0c00a720bbf5d42a3 Mon Sep 17 00:00:00 2001 From: etienne-alby <68907958+etienne-alby@users.noreply.github.com> Date: Sun, 25 Oct 2026 22:20:16 +0100 Subject: [PATCH 3/3] Nutrient DWS: ask the hosted Markdown for headers, footers and picture words When output.markdown is the graded body, send includeHeadersAndFooters and extractWordsFromPictures. The graph body keeps that text, so both bodies are asked for the same content. The graph request is unchanged. --- .../inference/providers/parse/nutrient_dws.py | 18 ++++++++++---- .../parse/test_nutrient_dws_errors.py | 24 +++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/parse_bench/inference/providers/parse/nutrient_dws.py b/src/parse_bench/inference/providers/parse/nutrient_dws.py index e4d48a4d..c09af665 100644 --- a/src/parse_bench/inference/providers/parse/nutrient_dws.py +++ b/src/parse_bench/inference/providers/parse/nutrient_dws.py @@ -1,7 +1,8 @@ """Provider for Nutrient DWS Data Extraction PARSE. Only options from the published contract are sent (``format``/``formats``, -``includeWords``, ``enableInlineFormatting``). Unknown options are accepted and +``includeWords``, ``enableInlineFormatting``, and with the hosted body +``includeHeadersAndFooters`` and ``extractWordsFromPictures``). Unknown options are accepted and ignored rather than rejected. Credits are charged per page. ``usage.data_extraction_credits.cost`` is recorded @@ -170,16 +171,23 @@ def _instructions(self) -> str: # `includeWords` defaults to false and carries the style flags the # formatting rules score. `enableInlineFormatting` defaults to false and # writes those styles into `output.markdown` (the body when `body_source` - # is "hosted"); the graph body styles itself from the word flags. The - # other Markdown switches (`useHtmlTables`, `enableSemanticBlockFormatting`, - # `includeHeadersAndFooters`, `extractWordsFromPictures`) keep the defaults - # DWS documents and pins for every Markdown request, so they aren't sent. + # is "hosted"); the graph body styles itself from the word flags. + # When `output.markdown` is the graded body, `includeHeadersAndFooters` + # and `extractWordsFromPictures` (both default false) are switched on: + # the graph body keeps running headers, footers and the words inside + # pictures, so the hosted body is asked for the same content. The graph + # body never reads `output.markdown`, so its request is unchanged. The + # other Markdown switches (`useHtmlTables`, `enableSemanticBlockFormatting`) + # keep the defaults DWS documents and pins, so they aren't sent. if self._spatial: output: dict[str, Any] = { "formats": ["markdown", "spatial"], "includeWords": True, "enableInlineFormatting": True, } + if self._body_source == "hosted": + output["includeHeadersAndFooters"] = True + output["extractWordsFromPictures"] = True else: output = {"format": "markdown"} return json.dumps({"mode": self._mode, "output": output}) diff --git a/tests/parse_bench/inference/providers/parse/test_nutrient_dws_errors.py b/tests/parse_bench/inference/providers/parse/test_nutrient_dws_errors.py index 52887a61..4c707075 100644 --- a/tests/parse_bench/inference/providers/parse/test_nutrient_dws_errors.py +++ b/tests/parse_bench/inference/providers/parse/test_nutrient_dws_errors.py @@ -117,6 +117,30 @@ def test_spatial_modes_ask_for_words_and_inline_formatting(self) -> None: }, ) + def test_hosted_body_also_asks_for_headers_footers_and_picture_words(self) -> None: + for mode in ("structure", "understand", "agentic"): + provider = NutrientDwsProvider("nutrient_dws", {"mode": mode, "body_source": "hosted", "api_key": "test"}) + self.assertEqual( + json.loads(provider._instructions()), + { + "mode": mode, + "output": { + "formats": ["markdown", "spatial"], + "includeWords": True, + "enableInlineFormatting": True, + "includeHeadersAndFooters": True, + "extractWordsFromPictures": True, + }, + }, + ) + + def test_hosted_body_from_environment_also_asks_for_them(self) -> None: + with mock.patch.dict(os.environ, {"NUTRIENT_DWS_BODY_SOURCE": "hosted"}): + provider = NutrientDwsProvider("nutrient_dws", {"mode": "understand", "api_key": "test"}) + output = json.loads(provider._instructions())["output"] + self.assertIs(output["includeHeadersAndFooters"], True) + self.assertIs(output["extractWordsFromPictures"], True) + def test_text_mode_sends_only_the_markdown_format(self) -> None: provider = NutrientDwsProvider("nutrient_dws", {"mode": "text", "api_key": "test"}) self.assertEqual(json.loads(provider._instructions()), {"mode": "text", "output": {"format": "markdown"}})