OCI Document Understanding: Invoice and Form Data Extraction

OCI Document Understanding uses AI to extract structured data from documents: invoices, receipts, tax forms, ID cards, and custom form types. Pre-trained models handle common document types without training data. For custom forms specific to your organization, you train a model on labeled examples. The extracted data returns as structured JSON with key-value pairs, tables, and confidence scores per field. This replaces manual data entry and fragile OCR-then-parse pipelines.

Step 1: IAM Policy

resource "oci_identity_policy" "document_policy" {
  compartment_id = var.compartment_id
  name           = "oci-document-understanding-policy"
  statements = [
    "Allow group AIEngineers to manage ai-service-document-family in compartment id COMPARTMENT_OCID",
    "Allow dynamic-group ApplicationInstances to use ai-service-document in compartment id COMPARTMENT_OCID",
    "Allow service documentunderstanding to read object-family in compartment id COMPARTMENT_OCID",
    "Allow service documentunderstanding to manage objects in compartment id COMPARTMENT_OCID where target.bucket.name = 'invoice-extraction-output'"
  ]
}

Step 2: Batch Invoice Extraction Job

resource "oci_objectstorage_bucket" "invoice_inbox" {
  compartment_id = var.compartment_id
  namespace      = var.tenancy_namespace
  name           = "invoice-inbox"
  access_type    = "NoPublicAccess"
}

resource "oci_objectstorage_bucket" "invoice_output" {
  compartment_id = var.compartment_id
  namespace      = var.tenancy_namespace
  name           = "invoice-extraction-output"
  access_type    = "NoPublicAccess"
}

resource "oci_ai_document_processor_job" "invoice_batch" {
  compartment_id = var.compartment_id
  display_name   = "invoice-data-extraction-batch"

  input_location {
    source_type = "OBJECT_STORAGE_LOCATIONS"
    object_locations {
      namespace_name = var.tenancy_namespace
      bucket_name    = oci_objectstorage_bucket.invoice_inbox.name
      object_name    = "pending/"
    }
  }

  output_location {
    namespace_name = var.tenancy_namespace
    bucket_name    = oci_objectstorage_bucket.invoice_output.name
    prefix         = "extracted/"
  }

  processor_config {
    processor_type = "GENERAL"
    document_type  = "INVOICE"

    features {
      feature_type = "KEY_VALUE_EXTRACTION"
      tenancy_id   = var.tenancy_ocid
    }

    features {
      feature_type = "TABLE_EXTRACTION"
    }

    features {
      feature_type = "TEXT_EXTRACTION"
    }
  }

  defined_tags = { "Operations.ManagedBy" = "terraform" }
}

output "job_id" { value = oci_ai_document_processor_job.invoice_batch.id }

Step 3: Event-Triggered ERP Ingestion

resource "oci_events_rule" "invoice_extracted" {
  compartment_id = var.compartment_id
  display_name   = "invoice-extraction-complete"
  is_enabled     = true

  condition = jsonencode({
    "eventType" = ["com.oraclecloud.objectstorage.createobject"]
    "data"      = { "bucketName" = ["invoice-extraction-output"] }
  })

  actions {
    actions {
      action_type = "FAAS"
      is_enabled  = true
      function_id = var.invoice_ingestion_function_id
      description = "Ingest extracted invoice data into ERP"
    }
  }
}

Operational Notes

Use confidence scores from the extraction output to route documents for human review. Set a threshold: extractions above 95 percent confidence go directly to your ERP system. Extractions between 75 and 95 percent go to a review queue where a human validates the low-confidence fields. Extractions below 75 percent go to full manual processing. This tiered approach automates 70 to 80 percent of typical invoice volume without accepting accuracy risk on ambiguous documents.

The event-trigger pattern using OCI Events and Functions creates a fully serverless document processing pipeline: documents arrive in the inbox bucket, a Document Understanding job processes them, Events detects the new output file, and a Function ingests the structured data into your downstream system. No servers to manage, no polling loops to write, and the pipeline scales automatically with document volume.

Regards,
Osama

#OCI #OracleCloud #DocumentUnderstanding #AI #IDP #Terraform #IaC #TechBlog #Oracle #Automation #DocumentAI #OracleCloudInfrastructure #InvoiceProcessing #OCR #KeyValue #TableExtraction #BatchProcessing #ERPIntegration #CloudNative #Serverless

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.