Extract evidence from forms and media
Use an analyzer schema, track long-running analysis and validate structured fields before writing records.
Extract evidence from forms and media
Work through the decision
A receiving clerk uploads an invoice. The first response acknowledges the request but contains no amount. Should the importer post a record?
Check your reasoning
Keep the operation reference and obtain its terminal status. On success, read the analyzer’s structured fields and validate the amount, currency and document identity. On failure, record the error and present a review path. Acknowledgment only means the analysis was accepted.
Compare the choices
- Analyzer schema
- Define named fields, expected types and descriptions for the extraction task. Test representative missing or ambiguous values.
- Resource endpoint
- Initialize ContentUnderstandingClient with the intended service resource endpoint and an identity with the needed access.
- Long-running operation poller
- Keep the poller returned when analysis starts. Wait for successful completion and handle terminal errors before reading contents.
- Typed field validation
- Check field presence, type and domain rules before committing a value. Route uncertain or contradictory evidence to review.
- Image analyzer
- Use a suitable visual analyzer and schema for facts visible in still images, then check extracted values against the source photo.
- Audio or video analyzer
- Extract fields or events from media with a matching analyzer. Retain time evidence where available for human verification.
- Document or form analyzer
- Use a document-oriented analyzer for invoices, tables, forms and their page evidence. Verify field relationships across pages.
Test the decision
Define different schemas for a shipment form, a photograph of a crate and a recorded handoff. A document can supply line items, an image can supply visible condition, and a recording can supply spoken commitments or timestamped events. Reference source evidence so staff can check disputed values.
Inspect a completed analyzer result
With azure-ai-contentunderstanding and azure-identity installed, use the resource endpoint and an analyzer configured for invoices. Set INVOICE_ANALYZER to its ID. The local lab below exercises downstream checks without cloud resources.
import os
from pathlib import Path
from azure.ai.contentunderstanding import ContentUnderstandingClient
from azure.identity import DefaultAzureCredential
client = ContentUnderstandingClient(endpoint=os.environ["CONTENT_ENDPOINT"],
credential=DefaultAzureCredential())
operation = client.begin_analyze_binary(os.environ["INVOICE_ANALYZER"],
Path("delivery-invoice.pdf").read_bytes(), content_type="application/pdf")
for document in operation.result().contents:
invoice_date = (document.fields or {}).get("InvoiceDate")
print(invoice_date.value if invoice_date is not None else "review date")
Content Understanding client methods
Practice the guide skills
- Define invoice date, currency, total and line items in an analyzer schema. Reconcile the reported total and capture which page supports it. Watch 1:02:48
- Extract the condition and visible identifier of a crate from a labeled photo. Flag obscured characters for review. Watch 1:03:02
- Design an audio field for a spoken commitment and a video field for a handoff event. Locate the corresponding moments in the source clip. Watch 1:03:05
- Trace resource endpoint, analyzer ID, poller, terminal result and typed fields. Try a genuine zero, a missing amount and a failed operation. Watch 1:04:06
Official objectives for this lesson
Lab · Reconcile extracted invoice fields
Run this offline Python 3 exercise on normalized extraction fixtures. Decide which invoices a clerk should review. The acceptance rule requires a completed operation, a USD total and agreement with the sum of the lines to the cent.
from decimal import Decimal
records = [
("A", "Succeeded", "USD", "12.50", ["5.00", "7.50"]),
("B", "Running", None, None, []),
("C", "Succeeded", "USD", None, ["4.00"]),
("D", "Succeeded", "USD", "0.00", ["0.00"]),
("E", "Succeeded", "USD", "15.00", ["10.00", "4.00"]),
("F", "Failed", None, None, []),
]
def route(status, currency, total, lines):
if status == "Running":
return "poll again"
if status != "Succeeded":
return "operation error"
if currency != "USD" or total is None or not lines:
return "review fields"
expected = sum(Decimal(value) for value in lines)
return "ready" if Decimal(total) == expected else "review totals"
for invoice, *fields in records:
print(invoice, route(*fields))
Check the result
A ready B poll again C review fields D ready E review totals F operation error
The zero-dollar record passes because it contains an explicit total that reconciles. Missing and contradictory fields require distinct review paths. Change A to EUR or remove one line. This fixture assumes line amounts already include all taxes and discounts. Adapt the reconciliation rule to the actual invoice schema.
Related lesson · Model records and relationships in Dataverse
Extract evidence from forms and media quiz
Answer 3 questions. Check each answer for an explanation.