Bilingual PDF reader

A model-agnostic Laravel service that reads messy English and Arabic booking PDFs with OpenAI or Anthropic models, checks every answer against a JSON Schema, and pre-fills a booking form for a person to confirm.

Floors
B2reading roomB1offices
Stack
Laravel, OpenAI, Anthropic, JSON Schema, pdftotext, Imagick

What it is

A Laravel service that reads hotel booking confirmations, the PDFs suppliers send in English, Arabic or both, and turns them into a structured booking. An agent uploads a PDF to the booking form, a model reads it, the answer is checked against a JSON Schema, and the form fills itself in for the agent to check and submit.

It's model-agnostic: any capable model from OpenAI or Anthropic can sit behind it, chosen in config. The design proved itself later, when another provider was added behind the same interface without touching anything that calls it.

The problem

Every supplier's confirmation looks different. Some are clean text and some are closer to scans. Some put Arabic and English side by side, and the details that matter, names, dates, rooms and totals in two currencies, sit in a different place on every one. Models read that kind of mess well. They're less good at admitting when they've guessed.

What I built

  • One interface for parsing, with drivers for OpenAI and Anthropic and a config switch between them
  • Three ways in: the extracted text, every page rendered as an image, or both together with the images winning; the Anthropic driver reads the PDF directly
  • A prompt that fills every field in English and Arabic, translates whichever side is missing, and keeps notes on anything it wasn't sure of
  • A JSON Schema for a booking, sent to the model as the response format where the provider supports it, and checked again when the answer comes back
  • A log of every parse: provider, model, tokens, timings and whether the answer passed

The interesting parts

Text and pictures

Extracted text is cheap, but it loses the layout, and Arabic can come out of a PDF in an order no person would read. Page images keep both, but a model can misread a digit in a picture. So the combined method sends the text and every page as an image in one request, and tells the model the images are the source of truth when the two disagree.

Model-agnostic, for real

Code that needs a booking sees one interface: give it a PDF, get a booking back. Which provider and which model answer is a config value. Each driver deals with its own provider's quirks, like structured output on one side and a strict example on the other, so the rest of the app never has to.

Checked, never trusted

The model never saves anything. Its answer has to pass the schema, and even then it only pre-fills a form that a person submits. The model's notes about guesses and conflicts are shown beside the form. When an answer fails the schema, it's logged and the form stays empty, because a half-right booking is worse than a blank one.

Ring the bell

Want something like this built, or one of these explained? The intercom is downstairs.

Get in touch