Putting it all together

You have built every piece of the extraction pipeline. In this final lesson, we walk through how the pieces fit together so you can ship the service with confidence. Upload validation, base64 encoding, schema-driven extraction, currency detection, and confidence scoring all meet in one request flow.

The full extraction pipeline

Every stage of the request lifecycle from upload to validated output.

invoice_analyzer.py
python
async def analyze_invoice(
    self,
    base64_content: str,
    mime_type: str,
) -> InvoiceDataWithConfidence:
    """End-to-end extraction with validation and confidence scoring."""
    # Guard: reject unsupported PDF + provider combos
    if mime_type == "application/pdf" and not self._supports_pdf():
        return InvoiceDataWithConfidence(
            is_invoice=False,
            vendor_name="Error: PDF not supported with this provider.",
        )

    # Build multimodal payload
    content = self._build_multimodal_content(base64_content, mime_type)

    # Call the vision LLM
    response_text = await self.llm_provider.generate_text(content)

    # Clean, parse, and validate
    clean_json = self._strip_markdown_fences(response_text)
    data = json.loads(clean_json)
    return InvoiceDataWithConfidence(**data)

One method ties every earlier concept together: provider compatibility check, multimodal payload, LLM call, JSON cleanup, and Pydantic validation with confidence scores.

Validation checklist: Deployment readiness checklist

Loading practice…

Checkpoint: Production extraction checkpoint

Loading practice…