Impact-Site-Verification: 578d421e-1081-463d-918b-ec5e29c5b9db
<Back

Major Life Insurer: Automated Business-Analysis Tables from Operations Manuals

Global Consulting Firm

Context and Problem

With a teammate, built a pipeline that automates extracting tasks from operations manuals and assessing whether each can be automated with AI. The manuals came as PDF, Word, Excel, and PowerPoint.

Pipeline and Data Flow (Team Output)

Four stages (convert, extract, classify, group), each writing its result to a numbered folder: received files, PDF, Markdown, extracted tasks, classified tasks, groups, and business overview. The extraction, classification, and grouping logic (prompts, category definitions, CSV columns) was mainly my teammate's work.

  1. Convert: Office files go through LibreOffice to PDF, then Gemini turns them into Markdown.
  2. Extract: pull out three levels: category, process, and task.
  3. Classify: label each task by replacement technology, e.g., API integration, OCR, or not automatable.
  4. Group: attach user-facing action groups and write the result as CSV.

What I Designed and Built

My part was turning the pipeline into something people could run: the repository structure and refactoring, the web UI, the asynchronous converter, Docker, and the user manual.

  1. Web UI: built with FastAPI and Jinja2, with htmx, Alpine.js, Tailwind CSS, and Mermaid on the page. Uploading and listing files, marking the main manual (extraction receives it first, then the supporting documents), running or cancelling each stage, and viewing and downloading results (UTF-8 or CP932, so the CSV opens directly in Japanese Excel) all happen on one screen.
  2. Progress and run control: sse-starlette sends Server-Sent Events (progress, complete, ping) that the browser receives with EventSource. Stages run in order, blocking work is moved to worker threads to keep the event loop free, and the business overview is generated in the background while extraction runs.
  3. Parallel conversion: several files are converted at once, with concurrent Gemini calls capped at 50 by an asyncio.Semaphore. PDFs over 20 pages are split into 15-page chunks with PyMuPDF, converted in order, and merged. Each chunk is uploaded through the Gemini Files API and always deleted afterwards.
  4. Structured output: Gemini's structured output receives the JSON schema of a Pydantic model, and the response is validated against that type.
  5. Runtime and manual: a Dockerfile and Docker Compose setup with Japanese fonts (Noto CJK and IPA) and LibreOffice in the image, hot reload for development, and a separate profile for batch runs. Also wrote the user manual that explains how to read the classification.

Technical Decisions

  1. No LangGraph: the planned conversation flow fit in FastAPI, this avoided learning cost and an extra dependency, and LangGraph could still be added later, so the system stayed a plain stage-by-stage pipeline. The plan also recorded when to revisit: multi-session chat, five or more branches, or concurrent users.
  2. Changes for speed (effect not measured): raised the concurrency cap from 5 to 20 and then 50, moved every stage to a lighter Gemini model, and cut retries, since structured output with a JSON schema should succeed in one call.
  3. Overview diagram: LLM-generated Mermaid sometimes fails to render, so the code tries a regex auto-fix, syntax validation, and up to three LLM repair rounds in turn, and keeps the regex-fixed diagram if all of them fail.

How It Was Verified

  1. Tests: wrote tests for the conversion helpers, the formatting of the source column in results, and integration tests for the file API.
  2. Run record: the pipeline ran end to end on the material received from the client (output accuracy not evaluated).

Technologies

Python 3.12uvGemini APIFastAPIJinja2htmxAlpine.jsTailwind CSSMermaidServer-Sent EventsPydanticPyMuPDFpandasLibreOfficeDockerDocker Composepytest