What actually runs when you press refresh?
I wanted a reader to be able to question a number and follow it back to the report. That shaped the implementation: keep the source with the data, calculate in Python, and let the interface show both the result and how it was reached.
Follow one number through the system
Page 17 of the report lists fourth-quarter net sales of 13,336 USD million for 2025 and 13,153 for 2024. The local dataset keeps those two values together with their unit, period and source reference.
Python calculates 13,336 − 13,153 = +183. FastAPI returns that result as JSON, and React draws the net-sales bar. Six other contributions bring the total change in operating income to +86 USD million.
That explains where the movement comes from arithmetically. Explaining why the business changed is a separate task, using the company’s commentary and keeping it attributed to the report.
Five decisions behind that simple chart
Start with reviewed source data
The figures come from the public Novartis report. Selected tables were transcribed into JSON and checked against the report. Each fact retains its period, unit, accounting basis and source page. This version does not automatically extract or understand an arbitrary PDF.
Validate and calculate in Python
The backend checks the shape and meaning of the input, including expense signs, compatible periods and complete financial lines. Ordinary Python arithmetic produces the changes, margins, shares and reconciliation checks. An LLM does not calculate these numbers.
Expose the calculation through FastAPI
backend/app.pydefines the HTTP routes.GET /api/reviewbuilds the focused quarterly review;GET /api/reportbuilds the wider explorer dataset. These routes call the Python functions on the server and return JSON.Let the interface ask different questions
The React page displays the returned dataset as charts and tables. Period changes, product sorting and source searches happen in the browser. Refreshing makes a new request to the Python service. The page labels whether it is showing that response or a saved calculation.
Try inputs that should fail
The test suite changes signs, periods, units and totals on purpose. A test passes when the calculation rejects the bad input. Saved-output checks also compare a fresh calculation with the version shipped in the site. These tests check this dataset and its rules, not the financial accuracy of every possible document.
What runs on Vercel, and what runs in the browser?
The Next.js site serves the pages and React controls. The Python application is deployed separately within the same project as a Vercel Function, entered through api/index.py. Requests under /api/ are routed to that FastAPI application.
Changing a chart filter uses data already in the browser. Pressing refresh calls the Python service and requests a fresh calculation. Neither action asks an LLM to calculate a financial value.
This excerpt is read directly from the backend source when the site is built. FastAPI registers the URL; build_review() does the work.
@application.get("/api/review")
def review():
report = build_review()
report["model"] = current_model_status()
return reportThe service’s interactive API documentation lets you inspect the routes and responses. The calculation pipeline and tests check the financial response before it reaches the chart.
A chart can add up and still be wrong.
If both years’ operating-income totals are wrong by the same amount, the error cancels out when you subtract them. Checking only the change would miss it. Both original income statements must also reconcile.
income, sales = by_id["operating_income"], by_id["net_sales"]
delta = income["current"] - income["prior"]
residual = delta - sum(c["delta"] for c in contributions)
# Reject an offsetting error that reconciles deltas but breaks both P&L totals.
for period in ("prior", "current"):
if sum(by_id[key][period] for key in CONTRIBUTION_IDS) != income[period]:
raise ValueError(f"{period} income-statement total does not reconcile")
if residual:
raise ValueError("the income movement does not reconcile")A test changes both totals by the same amount to make sure the validator catches exactly that problem. Another changes an expense to a positive number. The wider report applies similar checks to income, cash, balance-sheet totals and the company’s non-IFRS reconciliations.
Why keep a saved result?
The portfolio should still be readable when its Python service is unavailable. The saved JSON is a generated artifact from the same code, with source identifiers and validation results. It is a fallback, not evidence that a request ran successfully. That is why the mode stays visible.
Where AI helped, and where it is being tested
I used Codex to help build this example and independent agents to check its figures and claims. The source choices, expense signs, reconciliation rules and displayed results are the parts I need to review. Generating the code does not settle those decisions.
This explorer uses ordinary code for the calculations and fixed text for its brief. In the separate Finance evidence desk, I tested whether a second AI agent improves a generated explanation. That page shows recorded model responses and measured results. Keeping the two flows separate makes it possible to inspect the arithmetic before judging the writing.
Inspect or run it yourself
The source package includes setup instructions and pinned dependencies. The public site runs the Python service as a Vercel Function. For local development, the same application can run with Uvicorn. The data comes from the published report.