Pydantic AI PDF parsing with GPT-5.4-mini and Phoenix
Learn to extract bank statements into Pydantic models, check transaction totals, and review runs with Phoenix on localhost:6006.
Player not loading? Watch on YouTube
This Python tutorial follows a bank statement through PDF extraction, structured output and accuracy checks with Pydantic AI. The speaker sets up the project with uv and sends the file through BinaryContent with the application/pdf media type. The example uses OpenAI's GPT-5.4-mini, identified as the March 17, 2026 version. It sends PDF content to OpenAI; the local components shown are the script and evaluation tools.
Pydantic models define transaction descriptions, amounts and dates, plus statement-level fields. Setting the agent's output type makes the results accessible as Python objects. The first structured response includes a beginning balance as a transaction, so the demonstration also shows why a valid output shape does not establish extraction accuracy.
The speaker adds an is_bank_statement flag and checks whether the beginning balance plus transaction totals equals the ending balance. Repeated runs produce both matching and mismatching results. Retries and prompt changes are discussed as possible responses, rather than guarantees of correctness.
Phoenix runs at localhost:6006 and records requests and outputs in a local SQLite database. The speaker then uses Claude Code as a coding assistant to build a Flask evaluation app at localhost:5000. It displays the original PDF beside extracted transactions and lets the reviewer record feedback, with prompt and output history available for comparison.