Skip to main content
A
Docs

Extraction

Extract structured fields, tables, and dates from Arabic documents using LLM-powered analysis.

Structured Data Extraction

After a document has been OCR-processed and classified, the extraction stage pulls out structured data: key-value fields, tables, and dates. The extractor uses an LLM to analyze the raw text and return typed, confidence-scored fields.

This transforms unstructured document content into machine-readable data that can feed into databases, workflows, and downstream systems.

Running Extraction

curl -X POST "http://localhost:8008/api/v1/docs/extract?document_id=DOC_ID"

Response:

{
  "fields": [
    {"key": "full_name", "value": "Ahmed Al Maktoum", "confidence": 0.97, "field_type": "text"},
    {"key": "id_number", "value": "784-1990-1234567-1", "confidence": 0.99, "field_type": "text"},
    {"key": "nationality", "value": "UAE", "confidence": 0.96, "field_type": "text"},
    {"key": "expiry_date", "value": "2028-03-15", "confidence": 0.94, "field_type": "date"},
    {"key": "date_of_birth", "value": "1990-07-22", "confidence": 0.93, "field_type": "date"}
  ],
  "tables": [],
  "dates": ["2028-03-15", "1990-07-22"],
  "summary": "Emirates ID card for Ahmed Al Maktoum, expiring March 2028"
}

Response Fields

FieldTypeDescription
fieldsarrayExtracted key-value fields with types and confidence
tablesarrayExtracted tabular data (rows and columns)
datesstring[]All dates found in the document (ISO 8601)
summarystringLLM-generated one-line summary of the document

Field Object

PropertyTypeDescription
keystringField name (e.g., full_name, id_number)
valuestringExtracted value
confidencefloatExtraction confidence (0.0-1.0)
field_typestringData type: text, date, number, currency, phone, email

Extraction by Document Type

The extractor adapts its behavior based on the document classification:

Identity Documents

Expected FieldsExample Value
full_nameAhmed Mohammed Al Maktoum
full_name_arأحمد محمد آل مكتوم
id_number784-1990-1234567-1
date_of_birth1990-07-22
expiry_date2028-03-15
nationalityUAE
genderMale

Financial Documents

Expected FieldsExample Value
vendor_nameDubai Electricity & Water Authority
invoice_numberINV-2024-005678
total_amount1,234.50 AED
due_date2024-02-28
payment_statusPending

Government Documents

Expected FieldsExample Value
issuing_authorityMinistry of Interior
reference_numberMOI-2024-001234
subjectTrade License Renewal
issue_date2024-01-15
recipientAl Futtaim Group LLC

Table Extraction

For documents containing tabular data (invoices with line items, financial statements with rows), the extractor identifies and structures table content:

{
  "tables": [
    {
      "headers": ["Item", "Quantity", "Unit Price", "Total"],
      "rows": [
        ["Office supplies", "10", "25.00 AED", "250.00 AED"],
        ["Printer cartridge", "2", "150.00 AED", "300.00 AED"]
      ]
    }
  ]
}

Validation

After extraction, the validation step checks for completeness and format correctness:

curl -X POST "http://localhost:8008/api/v1/docs/validate?document_id=DOC_ID"
{
  "is_valid": true,
  "completeness_score": 0.85,
  "issues": [
    {"field": "nationality", "issue": "Missing required field", "severity": "warning"},
    {"field": "expiry_date", "issue": "Date is in the past", "severity": "info"}
  ]
}

Validation Checks

CheckDescription
Required fieldsExpected fields for the document type are present
Format validationDates are valid, ID numbers match expected patterns, phone numbers are well-formed
Completeness scorePercentage of expected fields that were successfully extracted
Cross-field consistencyDates are logical (birth date before expiry), amounts sum correctly

Low Confidence Fields

Fields with confidence below 0.80 should be flagged for human review. The validation endpoint surfaces these automatically in the issues array.

Chat RAG Ingest Pipeline

Docs AI integrates with Anar Chat's knowledge base through an ingest pipeline. Extracted and validated documents can be pushed to Chat's RAG system, making document content searchable and retrievable via the AI assistant.

This enables workflows where a citizen uploads a document, Docs AI processes it, and Chat can immediately answer questions about the document's content.

Configuration

VariableDefaultDescription
LLM_MODELllama-3.3-70b-versatileLLM for classification and extraction
LLM_ARABIC_MODELallam-2-7bArabic-optimized LLM
GROQ_API_KEYGroq API key (required)