Google Cloud Document AI (Document AI) is a service for parsing structured information from unstructured or semi-structured documents using state-of-the-art Google AI, including natural language processing, computer vision, translation, and AutoML. It helps automate tedious tasks, improve data extraction, and gain deeper insights from documents. The Python client library, currently at version 3.14.0, is part of the actively maintained `google-cloud-python` monorepo, receiving frequent updates.
pip install google-cloud-documentaiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to process a raw PDF document using a Document AI processor. It requires setting up authentication, a Google Cloud project, and an enabled Document AI processor. Ensure `GOOGLE_APPLICATION_CREDENTIALS` environment variable points to your service account key file, or that Application Default Credentials are configured.
Migrate to a Google Cloud certified partner solution for human review and correction, or implement custom human review workflows.
Regularly check the Document AI release notes for processor version deprecations and plan migrations to newer, supported versions (e.g., `pretrained-foundation-model-v1.5-2025-05-05`).
Upgrade to Python 3.10 or a newer actively supported version.
Improve input document quality, preprocess images to enhance contrast/sharpness, fine-tune custom extractor models with more specific training data, or implement post-processing logic to correct common confusions.
Carefully review labeled documents for overlapping bounding boxes, ensure all labeled fields contain OCRable text, and systematically test training data. Deleting the latest revision of a faulty document from the dataset can sometimes resolve issues but may lead to data loss.
Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of your service account key JSON file (`export GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json`), or authenticate locally using `gcloud auth application-default login`. Ensure the service account has roles like 'Document AI User' or 'Document AI Viewer'.
Install or upgrade the library using `pip install --upgrade google-cloud-documentai`. If the error persists, ensure you don't have the deprecated `google-cloud` package installed (`pip uninstall google-cloud`).
Verify that your `processor_name` is in the correct format (`projects/{project_id}/locations/{location}/processors/{processor_id}`), GCS URIs are accessible and correctly formatted, `mime_type` accurately reflects the document content, and the document is not corrupted or exceeding size limits. Also, ensure the processor type matches the document being sent.Double-check the `project_id`, `location`, `processor_id`, and `processor_version` for typos and confirm they exist in your Google Cloud project. Ensure the Document AI API is enabled in the project, and any referenced GCS paths are correct and accessible.
Explicitly set the `api_endpoint` in the `DocumentProcessorServiceClient` client options to match the region where your processor is located. For example, for a processor in 'eu', initialize the client with `client_options=ClientOptions(api_endpoint='eu-documentai.googleapis.com')`.