Skip to content

[Submission] Document Processing w/ AI #88

@samingbar

Description

@samingbar

Project link

https://github.com/temporal-sa/document-processing-examples

Language

Python

Short description (max 256 chars)

Temporal-powered mortgage underwriting demo that uses Gemini OCR, policy-grounded AI analysis, deterministic workflows, and a FastAPI review app to turn synthetic loan documents into structured decisions with human-in-the-loop oversight plus traceability.

Long Description

This repository is a working demo of an AI-assisted mortgage underwriting system built on Temporal, Python, and Gemini. Instead of treating document extraction, risk analysis, and approval logic as a single opaque LLM call, it breaks the process into durable workflow steps that can be observed, retried, audited, and paused for human input. The result is a practical example of how to combine workflow orchestration with generative AI in a way that is more structured and operationally realistic than a standalone prompt-based prototype.

The core use case is mortgage loan origination. The system accepts synthetic application documents as scanned images, runs multimodal OCR with Gemini to extract a structured mortgage application, validates that output with Pydantic models, computes underwriting metrics such as debt-to-income and loan-to-value ratios, retrieves relevant policy text from a local underwriting PDF, and then generates specialist analyses for credit, income, assets, and collateral. A critic step reviews the analysis for missed risks or inconsistencies, and a final decision memo is produced with a recommendation, risk score, conditions, and rationale. The workflow also scans outputs for potential bias language and enforces deterministic policy-based hard stops before any final approval is returned.

One of the strongest aspects of the repo is that it shows two orchestration patterns side by side. The fixed-flow workflow is a deterministic baseline where specialists always run in the same order, which makes it easy to reason about and test. The embedded-agent workflow introduces a supervisor that decides which specialist should run next based on the case state and current risk signals, offering a more dynamic, agentic routing model while still staying inside Temporal's durability model. That contrast makes the repository useful both as a learning resource and as a reference for teams evaluating when fixed pipelines are sufficient and when adaptive sequencing adds value.

The repo also includes a lightweight FastAPI review application that turns the workflow into an end-to-end demo. Users can upload case images, trigger a workflow, inspect sanitized applicant data and underwriting outputs, and submit a human approval or rejection when a case is routed to manual review. Temporal signals and queries are used to implement that review gate cleanly, which is a useful example of human-in-the-loop workflow design.

Beyond the application logic, the project is set up as a solid engineering template. It uses modern Python tooling with uv, Ruff, pytest, coverage thresholds, and typed Pydantic models throughout. The repository includes synthetic datasets, generated PDFs and images, policy resources, tests, and documentation on Temporal primitives, patterns, and workflow authoring. Overall, this is a strong demonstration of durable AI orchestration for document-heavy decision workflows, with clear separation between deterministic workflow logic, non-deterministic AI activities, and human oversight.

Because the repo uses synthetic data and simplified rules, it is clearly framed as a demonstration rather than a lending system, which makes it easier to share, run locally, and discuss. For a code exchange audience, it is especially valuable as an accessible example of durable, policy-grounded, human-reviewed AI systems design in practice today.

Author(s)

Sam Ingbar -- Temporal Technologies

Metadata

Metadata

Assignees

Labels

code exchange submissionCode and/or content about Temporal!triageIssues that Temporal folk need to look atziggy reviewedPre-screened by ZiggyBot

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions