Building an LBO model with agents
How to separate reading deal documents from running the buyout math and checking the spreadsheet.
Deal documents and the buyout math
In a leveraged buyout, a buyer acquires a company using a mix of debt and sponsor equity, uses the company's operating cash flow to pay down debt over the holding period, and measures the return on that initial equity at exit. Because the purchase price, annual cash sweep, and exit valuation are connected, a small change in an early assumption carries through every year of the forecast. If an agent reads a confidential information memorandum (CIM), chooses underwriting assumptions, and writes spreadsheet formulas in a single pass, a misread table header and a flipped sign in a debt formula both look like reasonable return numbers at the end.
Separating document reading from the financial calculation keeps those problems distinct. In the six-stage workflow below, the first two stages are a proposed design for indexing deal documents and using role-separated agents to extract cited figures. The remaining four stages run locally in the Python example in the source explorer at the end of this article. Starting from a set of explicit assumptions, the code computes the five-year cash and debt schedule, runs underwriting cases and a sensitivity grid, compiles a three-tab spreadsheet, and checks the resulting formulas and cell values.
Six-stage workflow diagram showing Documents, Agents, Inputs, Cases, Workbook, and Readback.
Documents
CIM & financial tables
Proposed manifest indexing files, versions, and schedule locators.
Agents
Role-separated extraction
Proposed diligence, financial, thesis, synthesis, and review tasks.
Inputs
Typed observations & JSON
Validated Decimal parameters and fixed entry sources and uses.
Cases
Underwriting & 5×5 grid
Deterministic base, upside, downside, and 25 sensitivity runs.
Workbook
3 tabs & 92 formulas
Compiled Inputs, CashFlow, and Returns cells with formula manifest.
Readback
102 local checks & API read
Formula and numeric verification locally and on mocked Sheets readback.
- Documents connects to Agents (flow).
- Agents connects to Inputs (flow).
- Inputs connects to Cases (flow).
- Cases connects to Workbook (flow).
- Workbook connects to Readback (flow).
The handoff between reading documents and running the math is an explicit input file (inputs.json). Document analysis deals with incomplete or conflicting material, such as restated historical columns, trailing-twelve-month bridges, or missing figures that need to remain blank until an analyst decides how to treat them. Once those choices are recorded as model inputs, the calculator requires a complete, validated set of numbers before it runs a single year of the forecast.
Working across that boundary changes how you inspect the model when a number looks wrong. If Year 5 debt or sponsor equity is off, you can check first whether the spreadsheet formulas match the Python calculation, and then check how each assumption was chosen from the source schedules. Instead of auditing prose interpretation and arithmetic at the same time, you can verify each step against its own rules.
Role-separated agents for document extraction and review
A deal data room can include a narrative memorandum, an accounting schedule, and an updated management presentation that cover overlapping periods with different rounding scales or adjustment definitions. Before any agent extracts figures in this design, a manifest lists the confidential information memorandum, financial tables, and document versions so searches and table queries point to specific files, tabs, and rows.
The five agent tasks run sequentially, and the first two read the primary evidence manifest independently. First,
Nora reviews the narrative sections and commercial schedules for customer concentration, retention, contract terms, and operating risks. Next,
Elena reads the financial statements and supporting schedules from that same evidence manifest without receiving the diligence agent's output.
Five-stage agent workflow diagram showing Nora, Elena, Daniel, Liam, and Simon with their inputs and outputs.
Evidence manifest

Diligence · Nora
Detail
Diligence analyst Commercial and operational review Reads narrative sections and supporting tables for retention, concentration, and contract risks.
- Inputs
- evidence (document manifest)
- Output
- diligence analysis

Financial analysis · Elena
Detail
Financial analyst Financial schedule extraction Reads financial schedules directly from evidence without inheriting diligence prose.
- Inputs
- evidence (document manifest)
- Output
- financials analysis

Thesis · Daniel
Detail
Investment thesis analyst Underwriting case formulation Combines primary evidence with diligence and financial outputs to frame operating cases.
- Inputs
- evidence, diligence, financials
- Output
- thesis analysis

Synthesis · Liam
Detail
Synthesis writer Draft memo and model parameter assembly Assembles the three upstream workstreams into a unified draft and candidate model inputs.
- Inputs
- diligence, financials, thesis
- Output
- draft memo and candidate inputs

Evidence review · Simon
Detail
Evidence reviewer Direct review against source evidence Reviews the draft directly against primary evidence without intermediate agent handoffs.
- Inputs
- evidence, draft
- Output
- reviewed draft
- Evidence manifest connects to Diligence · Nora (flow).
- Evidence manifest connects to Financial analysis · Elena (flow).
- Diligence · Nora connects to Thesis · Daniel (flow).
- Financial analysis · Elena connects to Thesis · Daniel (flow).
- Thesis · Daniel connects to Synthesis · Liam (flow).
- Synthesis · Liam connects to Evidence review · Simon (flow).
Withholding the diligence summary from the financial task avoids making an earlier prose summary the source for the numbers. Financial extraction must read the source schedules directly, keeping column headers, period boundaries, and footnote adjustments attached to each figure rather than inheriting another agent's summary. For example, when a presentation bridges reported operating income to adjusted EBITDA, the financial task is designed to record each proposed add-back with its file and table location instead of passing only the adjusted total.
The remaining three stages build on those initial outputs in sequence.
Daniel receives the primary evidence alongside the diligence and financials outputs to outline candidate underwriting cases and key operating levers.
Liam receives diligence, financials, and thesis to assemble a draft memo and candidate model inputs. Finally,
Simon receives only the draft and the original evidence, omitting the earlier agent handoffs so the review step compares the draft directly against the source documents.
Show proposed orchestration pseudocode
In this design, agents access the data room through scoped text search and read-only table tools that list sheets, describe columns, and run bounded queries. Tool permissions are enforced by the runtime harness outside the prompt: text inside a document supplies data to extract and evaluate, while any instructions or permission claims embedded in a file have no authority to change tool access or validation rules.
Structured output schemas define the fields required at each handoff, though a valid schema does not prove that an agent read a table header or economic definition accurately. Rather than forcing an agent to guess when a schedule omits a number, the design records a missing figure as None, keeps analyst assumptions separate from reported values, and flags conflicts when two documents disagree.
Typed financial observations and the entry transaction
To represent individual figures before they become model assumptions, the design uses a typed Observation record paired with one or more SourceRef locators that record the file, location, and period. Alongside the numeric amount (or None when a value is missing) and units, each observation tracks two separate attributes: whether the period is historical ("actual") or future ("forecast"), and whether the number was stated in a document ("reported"), computed from other figures ("calculated"), or chosen by an analyst ("assumed").
Separating the time period from how the number was produced avoids common labeling mix-ups. A management revenue projection printed in a CIM table is a "reported" "forecast", because the document states it directly for a future year. If a historical table gives revenue and an EBITDA margin percentage without printing dollar EBITDA, multiplying them produces a "calculated" "actual" observation that keeps both source references and the formula used. When the documents omit a future margin and I choose an underwriting margin for the model, that choice is recorded as an "assumed" "forecast" rather than presented as a disclosed figure.
The observation card below shows how those fields look for a single cell from our runnable example: Year 1 forecast revenue in CashFlow!C2. Because the local Python package starts directly from the manually supplied assumptions in examples/lbo/inputs.json rather than an automated document-extraction pipeline, this example record is a "calculated" "forecast" in USD millions formed by multiplying entry_revenue by 1 + revenue_growth.
- Metric
- Year 1 revenue (CashFlow!C2)
- Amount
- $108m
- Decimal value computed from validated base-case inputs
- Units
- USD millions
- Period
- Year 1
- Period type
- forecast
- First annual forecast period in the five-year schedule
- Origin
- calculated
- Derived from two input fields rather than directly reported in a deal document
CashFlow!C2=B2*(1+Inputs!$B$4)Source references
| File | Location |
|---|---|
inputs.json | entry_revenue$100m |
inputs.json | revenue_growth8% |
Traces both operands in examples/lbo/inputs.json
Show Python dataclass contract
Before the buyout calculator runs, it checks every field in inputs.json. All calculations run in Python Decimal arithmetic with 36-digit precision across a fixed five-year annual horizon in USD millions, and any missing or extra key stops the run immediately. Entry revenue and both valuation multiples must be positive, debt, transaction fees, and minimum cash must be zero or greater, revenue growth must stay above -1, and every margin, interest, tax, depreciation, capital expenditure, and working-capital rate must fall between 0 and 1 so a rate entered as 25 instead of 0.25 is rejected right away.
In the model's base case, entry revenue of $100m and an entry EBITDA margin of 25% establish $25m of entry EBITDA. The input file keeps that entry margin separate from the forecast EBITDA margin so historical and projected profitability can differ. Valuing entry EBITDA at a 10× purchase multiple gives an enterprise value of $250m, and adding $5m of transaction fees plus $5m of cash funded onto the balance sheet brings total uses to $260m. Financing the buyout with $125m of opening debt leaves $135m of initial sponsor equity, which must be positive under the model's 100% sponsor ownership convention with no rollover equity.
Entry sources and uses
USD millions| Line item | USD millions |
|---|---|
| Purchase enterprise value | 250.00 |
| Transaction fees | 5.00 |
| Funded minimum cash | 5.00 |
| Total uses | 260.00 |
| Opening debt | 125.00 |
| Initial sponsor equity | 135.00 |
| Exit enterprise value | 367.33 |
| Closing debt at exit | 57.48 |
| Closing cash at exit | 5.00 |
| Exit sponsor equity | 314.85 |
Management’s forecast and underwriting cases
When deal documents include a seller's multi-year projection, the proposed workflow keeps that schedule as a separate reported reference for comparison against the buyer's underwriting assumptions. Our runnable example includes no standalone management projection and evaluates three explicit underwriting cases (base, upside, and downside) rather than inventing a fourth calculated management case.
Each case in scenarios.json is a deterministic set of operating and exit overrides rather than a probability-weighted forecast or a Monte Carlo simulation. Compared with the base case, the upside case combines faster annual revenue growth with a higher forecast EBITDA margin and a higher exit multiple, while the downside case pairs slower growth with a lower forecast margin and a lower exit multiple.
When comparing operating cases, changing an entry parameter such as ebitda_margin, entry_multiple, or entry_debt alongside forecast assumptions changes the deal itself. If a downside case lowers the margin used to calculate entry EBITDA as well as future EBITDA, the model quietly prices the acquisition at a lower purchase price instead of testing how the same buyout performs under weaker operations.
To keep the purchase transaction constant across cases, the scenario runner allows overrides only on revenue_growth, forecast_ebitda_margin, and exit_multiple. The underlying calculator can evaluate different initial debt levels when you want to see how opening leverage changes the sponsor equity check and future interest expense, but the scenario comparison checks on every run that purchase enterprise value stays at $250m, opening debt stays at $125m, and initial sponsor equity stays at $135m.
Show scenario override loop
Each case recalculates the five-year schedule, compiles a fresh workbook, and runs all verification checks starting from that identical opening balance sheet. You can use the selector below to compare the three cases and inspect the five-year operating schedule, debt paydown, and Year 5 sponsor returns for each one.
Compare base, upside, and downside underwriting cases
Switch between the three deterministic cases to inspect how revenue growth, forecast EBITDA margin, and exit multiple change five-year cash flows and sponsor returns.
Interactive comparison table and five-year schedule for base, upside, and downside LBO cases.
Base
Case assumptions
- Revenue growth
- 8%
- Forecast EBITDA margin
- 25%
- Entry multiple
- 10×
- Exit multiple
- 10×
Exit returns
- Exit equity
- $314.85m
- Gross MOIC
- 2.33×
- Annualized return
- 18.5%
Case schedule
USD millions| Line item | Year 1 | Year 2 | Year 3 | Year 4 | Year 5 |
|---|---|---|---|---|---|
| Revenue | 108.00 | 116.64 | 125.97 | 136.05 | 146.93 |
| EBITDA | 27.00 | 29.16 | 31.49 | 34.01 | 36.73 |
| Free cash flow | 9.25 | 11.15 | 13.26 | 15.62 | 18.24 |
| Debt repayment | 9.25 | 11.15 | 13.26 | 15.62 | 18.24 |
| Closing debt | 115.75 | 104.61 | 91.34 | 75.72 | 57.48 |
| Closing cash | 5.00 | 5.00 | 5.00 | 5.00 | 5.00 |
Underwriting case comparison
| Case | Revenue growth (%) | Forecast EBITDA margin (%) | Entry multiple (×) | Exit multiple (×) | Exit equity (USD m) | Gross MOIC (×) | Annualized return (%) |
|---|---|---|---|---|---|---|---|
| Base | 8 | 25 | 10 | 10 | 314.85 | 2.33 | 18.5 |
| Upside | 10 | 27 | 10 | 10.5 | 420.4 | 3.11 | 25.5 |
| Downside | 5 | 22 | 10 | 9 | 178.39 | 1.32 | 5.7 |
How operating cash flow pays down debt and drives exit equity
In each year of the five-year forecast, the model converts revenue and EBITDA into free cash flow after cash interest and cash taxes, then sweeps available cash above the minimum balance into principal repayment. Annual cash interest is charged on the year's opening debt balance (opening_debt × interest_rate). Using opening debt avoids circular average-debt formulas, and every dollar of principal repaid at the end of one year lowers the opening debt balance and cash interest expense in the following year.
In Year 1 of the base case, growing entry revenue by 8% produces $108m of revenue and $27m of EBITDA at the forecast margin. Opening debt of $125m at the 8% interest rate costs $10m in cash interest. To calculate cash taxes, the model uses a taxable-income proxy (max(EBITDA - depreciation - interest, 0) × tax_rate), subtracting $2.16m of depreciation alongside interest before applying the 25% tax rate to arrive at $3.71m of cash taxes, without deducting non-cash depreciation a second time from cash flow. Subtracting cash interest, cash taxes, $3.24m of capital expenditures, and $800k for the increase in net working capital leaves $9.25m of Year 1 free cash flow before principal repayment.
Year 1 bridge from EBITDA to free cash flow
Step-by-step deductions taking Year 1 EBITDA of $27m to $9.25m of free cash flow after cash interest and cash taxes, before principal repayment.
USD millions
- Free cash flow
- 9.25
- Running balance ($m)
- 9.25
Data table
Year 1 cash conversion waterfall
| Bridge step | Amount ($m) | Running balance ($m) |
|---|---|---|
| EBITDA | 27.00 | 27.00 |
| Cash interest | −10.00 | 17.00 |
| Cash taxes | −3.71 | 13.29 |
| Capex | −3.24 | 10.05 |
| Change in NWC | −0.80 | 9.25 |
| Free cash flow | 9.25 | 9.25 |
Adding Year 1 free cash flow of $9.25m to the opening cash balance of $5m gives $14.25m of cash before the debt sweep. The model enforces a minimum cash floor of $5m: if cash before the sweep ever drops below that floor, the calculator raises a cash_shortfall error instead of inventing a revolving credit facility or silently covering the gap. Because all $9.25m of Year 1 free cash flow sits above the floor, the sweep (min(opening_debt, max(cash_before_sweep - minimum_cash, 0))) uses that cash to pay down opening debt of $125m to a closing debt balance of $115.75m. Closing cash finishes the year at $5m, and if debt is ever paid off completely, excess cash builds on the balance sheet above $5m.
Across the five-year schedule below, revenue growth and debt paydown work together. Each year's principal repayment lowers that year's closing debt, which becomes the following year's opening debt. A lower opening debt balance reduces the next year's cash interest charge and leaves more free cash flow available to pay down principal through Year 5, even as higher EBITDA and smaller interest deductions increase cash taxes.
Five-year revenue expansion vs. closing debt balance
Base-case revenue compounds at 8% per year from $100m at entry to $146.93m in Year 5, while the annual cash sweep reduces debt from $125m to $57.48m.
USD millions
Year 5
- Revenue
- 146.93
- Closing debt
- 57.48
Data table
Revenue growth and debt paydown
| Period | Entry | Year 1 | Year 2 | Year 3 | Year 4 | Year 5 |
|---|---|---|---|---|---|---|
| Revenue | 100.00 | 108.00 | 116.64 | 125.97 | 136.05 | 146.93 |
| Closing debt | 125.00 | 115.75 | 104.61 | 91.34 | 75.72 | 57.48 |
Five-year operating and debt schedule
USD millions| Line item | Entry | Year 1 | Year 2 | Year 3 | Year 4 | Year 5 |
|---|---|---|---|---|---|---|
| Revenue | 100.00 | 108.00 | 116.64 | 125.97 | 136.05 | 146.93 |
| EBITDA | 25.00 | 27.00 | 29.16 | 31.49 | 34.01 | 36.73 |
| Depreciation | — | 2.16 | 2.33 | 2.52 | 2.72 | 2.94 |
| Opening debt | — | 125.00 | 115.75 | 104.61 | 91.34 | 75.72 |
| Cash interest | — | 10.00 | 9.26 | 8.37 | 7.31 | 6.06 |
| Cash taxes | — | 3.71 | 4.39 | 5.15 | 6.00 | 6.93 |
| Capital expenditures | — | 3.24 | 3.50 | 3.78 | 4.08 | 4.41 |
| Change in NWC | — | 0.80 | 0.86 | 0.93 | 1.01 | 1.09 |
| Free cash flow | — | 9.25 | 11.15 | 13.26 | 15.62 | 18.24 |
| Opening cash | — | 5.00 | 5.00 | 5.00 | 5.00 | 5.00 |
| Cash before sweep | — | 14.25 | 16.15 | 18.26 | 20.62 | 23.24 |
| Debt repayment | — | 9.25 | 11.15 | 13.26 | 15.62 | 18.24 |
| Closing debt | 125.00 | 115.75 | 104.61 | 91.34 | 75.72 | 57.48 |
| Closing cash | 5.00 | 5.00 | 5.00 | 5.00 | 5.00 | 5.00 |
| Cash shortfall | — | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 |
By Year 5, base-case revenue reaches $146.93m and generates $36.73m of exit EBITDA, which values the business at $367.33m at the 10× exit multiple. Under 100% sponsor ownership, with no management rollover, interim distributions, or exit fees, paying off the remaining $57.48m of Year 5 closing debt and adding $5m of closing cash determines net sponsor equity proceeds at exit: . Dividing exit sponsor equity by the initial equity check gives the gross multiple on invested capital: .
Year 5 bridge from enterprise value to sponsor equity
Base-case exit enterprise value of $367.33m less $57.48m of remaining debt plus $5m of closing cash produces $314.85m of sponsor equity.
USD millions
- Exit equity
- 314.85
- Running balance ($m)
- 314.85
Data table
Year 5 exit equity waterfall
| Bridge step | Amount ($m) | Running balance ($m) |
|---|---|---|
| Exit EV | 367.33 | 367.33 |
| Closing debt | −57.48 | 309.85 |
| Closing cash | +5.00 | 314.85 |
| Exit equity | 314.85 | 314.85 |
Because the transaction has one initial equity outflow at closing, no interim cash distributions during the five-year hold, and one final equity inflow at the end of Year 5, the gross annualized equity return is MOIC^(1/5) - 1, or 18.5% in the base case. That five-year exponent matches a periodic spreadsheet IRR calculation across equal annual steps, whereas a deal with interim dividends, staged equity checks, or uneven cash-flow dates requires a dated schedule or XIRR.
Sensitivity across growth and exit multiples
While the three underwriting cases move revenue growth, forecast margin, and exit multiple together, an analyst also needs to isolate how operating growth and exit valuation affect returns independently. A two-dimensional sensitivity grid separates the return contribution of five-year cash generation and debt paydown from the multiple applied to terminal EBITDA at exit.
To map those two levers across a 5 × 5 matrix, the sensitivity runner crosses five annual revenue growth rates (4% to 12%) with five exit EBITDA multiples (8× to 12×), holding the forecast EBITDA margin at its base level and keeping the entry transaction fixed. Rather than estimating cells with a shortcut approximation, the runner computes the full five-year schedule, compiles a workbook, and runs verification for each of the 25 combinations in the grid below.
25-point sensitivity grid across revenue growth and exit multiples
Select any cell in the 5 × 5 matrix to view the annual revenue growth rate, exit EBITDA multiple, and annualized equity return for that coordinate.
Annualized equity return
5 by 5 sensitivity table crossing five annual revenue growth rates with five exit EBITDA multiples.
Exit multiple
Revenue growth
Selected cell
- Revenue growth
- 8%
- Exit multiple
- 10×
- Annualized equity return
- 18.5%Base
Sensitivity grid across revenue growth and exit multiples
Growth and exit multiple sensitivity
Annualized equity return (%)| Exit multiple | |||||
|---|---|---|---|---|---|
| Revenue growth | 8× | 9× | 10× | 11× | 12× |
| 4% | 6.1 | 9.4 | 12.4 | 15.1 | 17.6 |
| 6% | 9.3 | 12.5 | 15.5 | 18.1 | 20.6 |
| 8% | 12.3 | 15.6 | 18.5 | 21.1 | 23.5 |
| 10% | 15.3 | 18.5 | 21.3 | 24 | 26.4 |
| 12% | 18.1 | 21.3 | 24.2 | 26.8 | 29.2 |
The center cell of the grid above matches the base case: at 8% annual revenue growth and a 10× exit multiple, the buyout produces 2.33× gross MOIC and an annualized equity return of 18.5%. Selecting any cell in the grid displays that coordinate's revenue growth rate, exit multiple, and annualized equity return, while the generated model artifact retains the underlying five-year schedule and exit bridge for all 25 runs.
- Gross MOIC
- 2.33×
- Base-case multiple on initial sponsor equity
- Annualized return
- 18.46%
- Five-year gross sponsor equity return (MOIC^(1/5) − 1)
- Exit sponsor equity
- $314.85m
- Year 5 enterprise value less closing debt plus closing cash
Moving down a column and moving across a row act on different parts of the model. Increasing revenue growth down a column changes every year of the operating schedule: higher revenue requires larger annual working-capital and capital-expenditure investments, produces more EBITDA and cash taxes, and generates more cumulative free cash flow to retire debt, which lowers subsequent interest expense. Moving across a row changes only the exit multiple applied to Year 5 EBITDA, revaluing the business at exit while leaving the five-year operating cash flows and closing debt schedule unchanged.
Across all 25 combinations in this grid, annual free cash flow remains positive and the company repays debt in every period while keeping closing cash at the minimum floor. Consequently, this matrix maps return sensitivity across cash-generative operating trajectories; locating the exact revenue contraction or margin compression that triggers a cash_shortfall exception or halts debt repayment requires testing steeper downside inputs outside this grid's range.
Compiling the workbook and two-pass Google Sheets writes
Even when Python computes every schedule in Decimal, financial review still happens in a spreadsheet where reviewers click cells to inspect formulas and trace references across tabs. Writing static numbers into a grid produces a dead table that cannot be stress-tested; a useful export compiles the validated inputs into a multi-tab workbook whose formulas match the calculator's exact rules.
In workbook.py, the compiler maps the model into 157 populated cells across Inputs, CashFlow, and Returns, keeping the entry EBITDA margin in Inputs!B3 separate from the forecast EBITDA margin in Inputs!B15 and placing the $5m minimum cash floor in Inputs!B9. Alongside the cell grids, it builds a formula manifest covering all 92 formula cells, including CashFlow!C6 (=C5*Inputs!$B$10) for Year 1 opening-debt interest, CashFlow!C13 (=MIN(C5,MAX(C12-Inputs!$B$9,0))) for debt repayment above the minimum cash floor, and CashFlow!C14 (=C5-C13) for closing debt.
CashFlow
USD millionsYear 1 cash interest on opening debt (CashFlow!C6) CashFlow!C6 multiplies Year 1 opening debt in C5 by the interest rate in Inputs!$B$10 (=C5*Inputs!$B$10). Charging interest on opening debt avoids circular average-debt references, and Year 1 debt repayment in C13 lowers the opening debt balance in Year 2 (D5).
When writing those tabs to the Google Sheets API with spreadsheets.values.batchUpdate (which writes cell values across ranges, distinct from structural spreadsheets.batchUpdate calls), the ValueInputOption setting controls how strings are stored. The export helper in export.py writes the workbook in two passes: Pass 1 sends all 157 populated cells with valueInputOption="RAW" so labels, numbers, and formula strings are stored as literal values without UI parsing; Pass 2 rewrites only the 92 manifest formula coordinates with valueInputOption="USER_ENTERED" so Sheets parses and evaluates each formula while leaving the 65 static label and assumption cells untouched.
Pass 1 · RAW literal write
valueInputOption = RAWCells written157
Cell Stored payload Inputs!B2100CashFlow!C13=MIN(C5,MAX(C12-Inputs!$B$9,0))Stored as literal stringWrites all 157 populated cells (labels, numeric inputs, and formula strings) as literal text and numbers without UI parsing.
Pass 2 · USER_ENTERED formula write
valueInputOption = USER_ENTEREDCells written92
Cell Stored payload Inputs!B210065 label and numeric assumption cells remain untouched in Pass 2.CashFlow!C13=MIN(C5,MAX(C12-Inputs!$B$9,0))Parsed as active formulaRewrites only the 92 manifest formula coordinates so Google Sheets parses and evaluates each expression.
Dual API readback check
valueRenderOption = FORMULA- 92
- Confirms all 92 formula strings match the trusted manifest verbatim.
valueRenderOption = UNFORMATTED_VALUE- 85
- Compares 85 unformatted numeric values against model.py within 0.000001 tolerance.
Tested in test_export.py with 7 mocked Google Sheets API unit tests; no live Sheets export was run for this article.
Show batchUpdate payload structure
Inside a Google Sheet, the CellData resource separates userEnteredValue (such as a formula string) from the read-only effectiveValue and formattedValue fields computed by the spreadsheet engine. Before export_to_sheets() makes any remote API call, its local preflight step recompiles the workbook from the artifact's inputs dictionary, checks that the passed workbook sheets and formula manifest match that fresh compilation in full, and runs the local verifier. Any modified workbook artifact is rejected before spreadsheets().create() is called.
The optional export helper accepts a caller-supplied authenticated Sheets service client configured with the required Google Sheets API scopes and does not manage credentials or change Google Drive sharing permissions. In test_export.py, seven unit tests check the preflight comparison, two-pass batch assembly, and readback assertions against mocked API responses; no live Google Sheets export was run for this article.
Verifying formulas, numeric values, and source provenance
Writing formulas to a spreadsheet does not prove that every cell evaluated as intended. After the two-pass write, export.py reads the sheet back twice via ValueRenderOption: once with valueRenderOption="FORMULA" to confirm that all 92 stored formula strings match the formula manifest verbatim, and once with valueRenderOption="UNFORMATTED_VALUE" to compare 85 calculated numeric cells against the Python model outputs without display formatting, rejecting any missing, boolean, non-finite, or mismatched number.
To run the same verification offline without a Google account, verify.py includes a local evaluator that parses cell coordinates, single-column ranges, arithmetic operators, and SUM, MIN, and MAX across all 92 numeric formula cells in the workbook. In total, the local verifier performs 102 checks within a 0.000001 tolerance in model units: it compares 85 named cell values from the evaluated workbook against the Python calculation and runs 17 accounting identity and bound checks across entry, all five forecast years, and exit.
- Entry funding identity: opening debt plus initial sponsor equity equals purchase enterprise value plus transaction fees and funded minimum cash.
- Annual roll-forward and cash floor: in every forecast year, opening cash plus free cash flow equals cash before the sweep, closing cash stays at or above the minimum cash floor, and opening debt less repayment equals closing debt.
- Exit equity bridge: Year 5 exit enterprise value minus closing debt plus closing balance-sheet cash equals net exit sponsor equity.
Checking formula strings against a manifest is necessary but insufficient on its own, because an agent that writes a flawed formula can update the manifest to match its mistake. Comparing the evaluated cell numbers against the independent Python calculation is what catches a silent sign error.
- Formulas evaluated
- 92
- Total verification checks
- 102
- All 92 evaluated workbook formulas return numeric values; comparing 85 named cell outputs to Python plus 17 accounting identity and bound checks produces 102 total checks.
- Numeric cell comparisons
- 85
- Balance & bound checks
- 17
- Live Google Sheets run
- Not executed (verified via 7 mocked API tests in test_export.py)
Mutation test · Sign flip in closing debtTarget cellCashFlow!C14
| Mutation test · Sign flip in closing debt | Formula | Year 1 closing debt |
|---|---|---|
| Trusted workbook | =C5-C13 | $115.75m |
| Mutated workbook | =C5+C13 | $134.25m |
Changing both CashFlow!C14 and its manifest entry to =C5+C13 passes a formula-string check, while numeric verification rejects the resulting debt and return mismatches.
Before any API call, export_to_sheets() recompiles the workbook from base inputs and rejects any modified sheet or manifest up front.
Show verification excerpt
The regression test in test_model.py shown above demonstrates that failure mode on Year 1 closing debt in CashFlow!C14. If an edit replaces =C5-C13 with =C5+C13 (adding the Year 1 debt repayment to opening debt instead of subtracting it) and updates the manifest entry to =C5+C13, a formula-string check against that mutated manifest still passes. When verify_model() evaluates the sheet and compares the 85 numeric cells against the Python calculation, however, Year 1 closing debt evaluates to $134.25m instead of $115.75m, producing numeric mismatches across the debt and return schedule that fail verification (and may trip on a downstream cell first). Separately, if that modified artifact is passed to export_to_sheets(), the export preflight rejects it before evaluation or API calls because the mutated sheet and manifest no longer match a fresh compilation from the base inputs.
Because model.py and verify.py implement the same modeling conventions, passing all 102 checks establishes that the compiled workbook and the Python calculator agree on the tested arithmetic under those rules, not that the business assumptions themselves are accurate. Arithmetic and formula agreement cannot prove that an input came from the right document version or historical period, which is why each extracted observation must carry its own source reference when revised forecasts arrive. You can use the source explorer below to inspect the complete Python model, scenario runner, workbook compiler, and test suite.
Five-stage pipeline diagram from inputs.json through model.py, simulations.py, workbook.py, and verify.py.
Validate inputs
inputs.json → validate_inputs()Checks exact key set, 5-year horizon, positive multiples, and rates in [0, 1].
Calculate model
model.py → calculate()Computes entry bridge, 5-year cash sweep, debt paydown, and sponsor returns in Decimal.
Run scenarios & grid
simulations.py → simulate()Evaluates 3 cases and 25 grid points while asserting an unchanged entry transaction.
Compile workbook
workbook.py → compile_workbook()Builds 157 cells across Inputs, CashFlow, and Returns plus the 92-formula manifest.
Verify & export
verify.py · export.pyRuns 102 local checks and preflights optional two-pass Google Sheets writes.
- Validate inputs connects to Calculate model (flow).
- Calculate model connects to Run scenarios & grid (flow).
- Run scenarios & grid connects to Compile workbook (flow).
- Compile workbook connects to Verify & export (flow).
- 1Because the model maintains a minimum cash balance and pays no interim dividends, the $5m of closing cash on the Year 5 balance sheet is added to net sponsor equity proceeds at exit (exit enterprise value minus closing debt plus closing cash).
- 2Computing annual cash interest on each year's opening debt balance keeps the five-year schedule non-circular across both Python and spreadsheet formulas without iterative solver macros.