Documents & data

Verifying Address Formats in Extracted Data

Standardize raw extracted text into clean address fields. Use structural text parsing to enforce consistent City, State, and Zip formatting.

To ensure extracted addresses are formatted consistently, standardize raw OCR strings into distinct schema fields like Street, City, State, and Zip Code using regular expressions and text anchor rules. Operating this address parsing workflow internally ensures consistent field structures across your downstream databases without requiring third-party postal database validation checks.

Standardize Components with Text Anchor Rules

Address parsing converts unstructured text blocks into clean database fields. When document processors capture scanned pages, address data frequently arrives as a single text block mixed across multiple lines. You can resolve this by parsing extracted text anchor ranges and entity properties directly from document response objects Google Cloud Document AI document response.

Build your internal cleaning script to scan strings from right to left using structural text anchors. Locate the standard five-digit postal code first, as it provides a stable boundary point. Next, isolate the two-letter state code directly preceding the postal code. Treat all remaining characters before the state boundary as the street address and city. This structural division standardizes inputs before writing records to your database.

Execute Parsing on Scanned Text

Consider a synthetic raw text string extracted from a scanned header block:

123 Main St, New York, NY 10001

Apply regular expressions and component boundary rules to split the raw string into explicit schema keys:

Raw Input: 123 Main St, New York, NY 10001
Step 1 (Zip Anchor): Extract '10001'
Step 2 (State Anchor): Extract 'NY'
Step 3 (Delimiter Split): Extract '123 Main St' and 'New York'

Result:
  Street: 123 Main St
  City: New York
  State: NY
  Zip: 10001

The resulting key-value pairs give your database structured entries without altering or hallucinating text that was not present in the original capture source.

Diagnose Misaligned Text Anchor Offsets

Address formatting failures typically occur when raw document text lacks standard comma delimiters or contains OCR character substitutions, such as reading the letter O instead of the number 0 in a postal code. These character errors break regular expression matching and shift city text into the street field Google Cloud Document AI document response.

Inspect document text revisions and entity validation outputs when field splits fail. If a missing comma causes two text lines to concatenate improperly, verify the character offsets recorded in the document layout structure. Correcting character-level extraction errors before applying string splitting rules prevents invalid component mapping across your batch records.

Verify Parsed Field Consistency

Validate all parsed address components against concrete schema rules before importing records into production systems:

Component Required Pattern Validation Rule
Street Text and numbers Length greater than 3 characters
City Alphabetic string Non-empty text string
State 2-letter uppercase Exact match against standard state code list
Zip 5-digit numeric String matches ^[0-9]{5}$

Flag any record that fails these validation rules for human review. Operations staff can inspect the original page image, adjust bounding text anchors, and confirm field assignments before final database commit.