From cd86ed6d80d02789567febe4c2652ddd6dc661d5 Mon Sep 17 00:00:00 2001 From: Andres Garcia Date: Thu, 12 Nov 2026 11:32:04 -0500 Subject: [PATCH] PLAT-9435: add thinking parameter to process_document and process_document_url Send thinking ("light" or "deep") in the request body when set, document it, and add tests and a README example. Co-Authored-By: Claude Sonnet 5.5 --- README.md | 9 +++++++++ tests/test_documents.py | 38 ++++++++++++++++++++++++++++++++++++++ veryfi/documents.py | 8 ++++++++ 3 files changed, 55 insertions(+) diff --git a/README.md b/README.md index bc8e332..96a3e16 100755 --- a/README.md +++ b/README.md @@ -103,6 +103,15 @@ response = client.process_document_url( ) ``` +Run thinking on the line items with `thinking` (`"light"` or `"deep"`; omit it to turn it off). Both `process_document` and `process_document_url` accept it, and `"deep"` takes longer than `"light"`. It only takes effect if thinking mode is enabled for your account. + +```python +response = client.process_document( + file_path="/tmp/receipt.jpg", + thinking="light", +) +``` + The response contains the extracted fields. A typical result looks like: ```python diff --git a/tests/test_documents.py b/tests/test_documents.py index 78692dc..8df66b2 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -1,3 +1,5 @@ +import json + import pytest import responses @@ -196,6 +198,42 @@ def test_process_document_url(): assert d == mock +@pytest.mark.parametrize("thinking", [None, "light", "deep"]) +@responses.activate +def test_process_document_thinking(thinking): + client = Client(client_id="v", client_secret=None, username="o", api_key="c") + responses.add( + responses.POST, + f"{client.versioned_url}/partner/documents/", + json={"id": 1}, + status=200, + ) + client.process_document(file_path="tests/assets/receipt_public.jpg", thinking=thinking) + body = json.loads(responses.calls[0].request.body) + if thinking is None: + assert "thinking" not in body + else: + assert body["thinking"] == thinking + + +@pytest.mark.parametrize("thinking", [None, "light", "deep"]) +@responses.activate +def test_process_document_url_thinking(thinking): + client = Client(client_id="v", client_secret=None, username="o", api_key="c") + responses.add( + responses.POST, + f"{client.versioned_url}/partner/documents/", + json={"id": 1}, + status=200, + ) + client.process_document_url(file_url="https://example.com/receipt.jpg", thinking=thinking) + body = json.loads(responses.calls[0].request.body) + if thinking is None: + assert "thinking" not in body + else: + assert body["thinking"] == thinking + + @responses.activate def test_get_documents(): mock = [ diff --git a/veryfi/documents.py b/veryfi/documents.py index 2c76335..cbd7a90 100644 --- a/veryfi/documents.py +++ b/veryfi/documents.py @@ -96,6 +96,7 @@ def process_document( file_path: str, categories: Optional[List] = None, delete_after_processing: bool = False, + thinking: Optional[str] = None, **kwargs, ) -> Dict: """ @@ -105,6 +106,7 @@ def process_document( :param file_path: Path on disk to a file to submit for data extraction :param categories: List of categories Veryfi can use to categorize the document :param delete_after_processing: Delete this document from Veryfi after data has been extracted + :param thinking: Extra LLM pass on the line items: "light" or "deep" (slower). Omit to turn it off. Needs thinking mode enabled for your account. :param kwargs: Additional body parameters :return: Data extracted from the document """ @@ -119,6 +121,8 @@ def process_document( "categories": categories, "auto_delete": delete_after_processing, } + if thinking is not None: + request_arguments["thinking"] = thinking request_arguments.update(kwargs) return self.client._request("POST", "/documents/", request_arguments) @@ -131,6 +135,7 @@ def process_document_url( external_id: Optional[str] = None, max_pages_to_process: Optional[int] = None, file_urls: Optional[List[str]] = None, + thinking: Optional[str] = None, **kwargs, ) -> Dict: """Process Document from url and extract all the fields from it. @@ -143,6 +148,7 @@ def process_document_url( :param max_pages_to_process: When sending a long document to Veryfi for processing, this parameter controls how many pages of the document will be read and processed, starting from page 1. :param boost_mode: Flag that tells Veryfi whether boost mode should be enabled. When set to 1, Veryfi will skip data enrichment steps, but will process the document faster. Default value for this flag is 0 :param external_id: Optional custom document identifier. Use this if you would like to assign your own ID to documents + :param thinking: Extra LLM pass on the line items: "light" or "deep" (slower). Omit to turn it off. Needs thinking mode enabled for your account. :param kwargs: Additional body parameters :return: Data extracted from the document. """ @@ -156,6 +162,8 @@ def process_document_url( "file_urls": file_urls, "max_pages_to_process": max_pages_to_process, } + if thinking is not None: + request_arguments["thinking"] = thinking request_arguments.update(kwargs) return self.client._request("POST", endpoint_name, request_arguments)