Google Cloud Document AI API returning no output

I’m stuck with Google Cloud Document AI and getting zero response from my Python script.

I set up everything properly - created a service account, downloaded the JSON credentials file, and configured the API access. But when I execute my code, absolutely nothing happens. No errors, no output, just silence.

Here’s my current implementation:

from typing import Optional
from google.api_core.client_options import ClientOptions
from google.cloud import documentai

# Configuration
my_project = "my-project-id"
region = "us"
processor_key = "my-processor-id" 
doc_file = "sample.pdf"
content_type = "application/pdf"
output_fields = "text,entities,pages.pageNumber"

def extract_document_data(
    my_project: str,
    region: str,
    processor_key: str,
    doc_file: str,
    content_type: str,
    output_fields: Optional[str] = None,
    version_id: Optional[str] = None,
) -> None:
    # Set up client with regional endpoint
    options = ClientOptions(api_endpoint=f"{region}-documentai.googleapis.com")
    service_client = documentai.DocumentProcessorServiceClient(client_options=options)
    
    # Build processor path
    if version_id:
        processor_name = service_client.processor_version_path(
            my_project, region, processor_key, version_id
        )
    else:
        processor_name = service_client.processor_path(my_project, region, processor_key)
    
    # Read file content
    with open(doc_file, "rb") as file_handle:
        file_data = file_handle.read()
    
    # Create document object
    input_doc = documentai.RawDocument(content=file_data, mime_type=content_type)
    
    # Build processing request
    api_request = documentai.ProcessRequest(
        name=processor_name,
        raw_document=input_doc,
        field_mask=output_fields,
    )
    
    # Process document
    response = service_client.process_document(request=api_request)
    processed_doc = response.document
    
    print("Extracted text from document:")
    print(processed_doc.text)

I’ve tested both OCR and custom extraction processors but neither produces any output. My terminal just shows the command prompt again with no feedback. What could be causing this silent failure? Any debugging tips would be appreciated.

Hit the same wall with Google Cloud Document AI last year. Those silent failures are a nightmare to track down.

Your code’s fine, but there are some common traps. Check your service account has Document AI API User role minimum. Make sure you’re actually calling the function. Wrap everything in try-catch to see what’s getting swallowed.

Honestly though? After banging my head against Google’s API for weeks, I just switched to Latenode for the whole document processing pipeline. No auth headaches, actual error messages, and you can chain workflows without writing tons of boilerplate.

Built a workflow that grabs invoices from email, extracts data, validates it, and sends to accounting. 10 minutes setup vs days of API debugging.

Visual builder shows exactly where things break, proper logging everywhere. Easy to add fallbacks or human approval when the AI screws up.