From Voice Message to Signed PDF in Thirty Seconds
A detailed look at the AI extraction pipeline inside Kaepsi: from Whisper transcription through Claude-powered structured extraction to geocoded address validation and signed PDF delivery.
One of the defining capabilities of Kaepsi is the ability to send a voice message and receive a finished invoice PDF within thirty seconds. This document describes the technical pipeline that makes this possible.
Step 1: Transcription
Incoming voice messages arrive as binary media files via the WhatsApp Business API. The first step is to download the media buffer and submit it to OpenAI's Whisper model. Whisper returns a German-language transcript with high accuracy for trade-domain vocabulary: invoice amounts, client names, and service descriptions are transcribed reliably even in the presence of background noise from a construction site.
Step 2: Structured Extraction
The transcript is passed to Claude with a structured extraction prompt. The model is asked to produce a JSON object conforming to our InvoiceExtractionResult schema, including the customer name, delivery address, line items (with quantities, units, and unit prices), service date, VAT rate, and optional discount fields.
The extraction runs with a retry loop: if the output fails schema validation or contains implausible data (for example, a quantity-price product that does not match the stated total), the system re-submits with the validation error as additional context, allowing the model to self-correct. A maximum of two retries is enforced to bound latency.
Step 3: Validation and Address Resolution
Before the draft is created, the extracted address passes through our resolution layer. The Google Maps Geocoding API normalises the address to a canonical form and returns geographic coordinates. If the geocoded result differs from the user's input, the system presents a confirmation dialogue, ensuring that "Musterstraße 3" does not silently become an address in a different postal district.
Step 4: Draft Creation and PDF Generation
The validated extraction result is written to PostgreSQL via Prisma. A request is then sent to our PDF microservice, which renders the invoice using a React and Puppeteer stack. The PDF is stored in Google Cloud Storage and a signed URL with a fifteen-minute TTL is generated for preview, alongside a ninety-day sharing URL for the customer portal.
A WhatsApp interactive message with confirmation and edit buttons is sent back to the user. Tapping confirm finalises the invoice, increments the invoice number counter (format: YY-NNNNNN, with SELECT FOR UPDATE to prevent duplicates under concurrent load), and marks the document as confirmed.
The entire pipeline, from voice message receipt to PDF delivery, completes in under thirty seconds under normal conditions. The user never opens a browser.