ENGINE 40
SFS-E40-TXF · FRANCHISE TAX · REV 2026-07-24 · PRODUCTION
PRODUCTION = runnable end-to-end, CI-backed, full test suite passing. All data fictional and seeded.
Franchise Tax Combined Apportionment
Is the tax on the combined return the tax the workpapers re-derive?
A group of affiliated development companies files one combined franchise (margin) tax return each fiscal year in the fictional State of Marran, and three things have to happen together for that return to be defensible. The affiliate roster is redrawn -- last year's members, plus the affiliates that joined, minus the ones that left -- and every affiliate not included this year has to be enumerated with a reason rather than quietly dropped. Consolidated group revenue is taken from the tax trial-balance workpaper, reduced by the group's elected deduction to a taxable margin, and apportioned to Marran by a single receipts factor, in-state receipts over everywhere receipts. And the tax is a derived figure: margin times apportionment times rate, in that order. This engine reads the seven artifacts the combined return carries -- the affiliate register and address tab, the combined-group continuity workpaper, the consolidated trial balance, the single-factor receipts workpaper, the margin worksheet, the tax summary and the return rollup -- and runs twenty-one deterministic controls over them. Is the file complete and the review date readable, are the affiliate ids unique and each affiliate addressed, registered and carrying a known status, which registrations renew inside the file's own lead-time window, does the roster rebuild from the prior year plus additions less removals, is every member registered and every removal reconciled against the excluded list, is each trial-balance line well-formed, uniquely numbered and attributed to a current member, do the receipts rows hold in-state as a subset of everywhere, do the stated totals sum the rows, does the apportionment factor recompute and stay inside [0.00%, 100.00%], does group revenue tie the trial balance, do the margin, the apportioned margin and the tax re-derive, does the summarised tax recompute end to end from the workpapers, and does the return total tie the summary and the roster. Every cent is compared with exact ==, every factor and rate is truncating integer basis-point arithmetic, and no source artifact is ever written back.
A combined franchise return is the rare tax number that is fully derivable and almost never re-derived. Nothing on its face looks wrong when it goes wrong. An affiliate falls off the roster between filings and the return still foots -- it simply taxes a smaller group than the one that earned the revenue, and no line on the return says so. A revenue line is attributed to an affiliate that is not a current member, or carries an id another line already used, and the consolidated base is quietly over- or under-stated. The receipts factor is struck against a denominator that no longer sums the rows beneath it, so the apportioned margin is a share the receipts do not support, and the error is invisible because the factor itself is a clean-looking percentage. Then the margin, the apportioned margin, the tax, the summary and the return total are each carried forward from the figure above them rather than recomputed from the base facts underneath. The engine rebuilds the roster from the prior list and this year's changes, sums revenue from the trial-balance lines, recomputes the factor from the receipts rows rather than the stated totals, and takes the whole tax through the same margin kernel the data was derived with, comparing with exact ==. It ships a planted-defect file for every registered control and states its benchmark as a command rather than a claim.
Architecture
functional block stack · static overviewSelect a layer
Seven control families run in registry order over each combined-return file. The first proves the others had something to read, because a control that passes on absent evidence reports assurance it never performed.
Key specifications
at a glanceWhat it does for you
plain termsA group of affiliated development companies files one combined franchise (margin) tax return each fiscal year in the fictional State of Marran. The return is not one entity's; it is the whole group's, apportioned to Marran by a single receipts factor, and preparing it means three things happen together. The combined group is redrawn -- last year's members, plus the affiliates that joined, minus the ones that left -- and every affiliate not included this year has to be enumerated with a reason, because an affiliate that quietly falls off the roster is revenue that leaves the combined base with nobody noticing. The margin is apportioned -- consolidated group revenue from the tax trial balance, reduced by the group's elected deduction, scaled by in-state receipts over everywhere receipts -- so a factor struck against a denominator that does not sum its rows is a tax computed on numbers nobody reconciled. And the tax itself is derived: margin times apportionment times rate, in that order, each step a place a figure can be carried forward instead of recomputed. None of the failures look wrong on the return. A member with no registration, a revenue line attributed outside the group, a line id used twice, a base that does not tie the trial balance, a margin that does not re-derive from the deduction, a summary that does not recompute from the workpapers -- each foots on its own face. They are also not judgment calls. They are set equalities and integer comparisons -- a roster against prior plus additions less removals, a total against the sum of its rows, a factor against in-state over everywhere floored to a basis point, a tax against the apportioned margin at the rate with exact == -- which a deterministic control settles better than a workbook inherited by whoever prepares the return this year.
The seeded demo runs every control over every combined-return file7. The CLI generates twenty-three fictional combined-return files -- one clean baseline and one carrying each of the twenty-two planted defects -- then runs all twenty-one controls over each. The clean file returns PASS with no flags; every defect file returns REVIEW or FAIL and names the control it tripped along with the reason that control exists.
An affiliate leaves the group and the roster still rebuilds8. In the baseline, AFF-04 is removed from the combined group and AFF-05 joins, so the stated roster must equal the prior four members plus the addition less the removal. One defect file adds a stray prior-year member without touching the stated list, and grp_roster_continuity fails with both the stated roster and the rebuilt one; another empties the excluded list, and grp_excluded_reconciled fails because the removal is no longer enumerated with a reason.
The determination is recomputed, not read back9. A defect file moves the summarised tax by one cent and moves the return total with it, so the rollup is internally consistent and only a recomputation can see the break. rpt_summary_recomputes rebuilds the tax from the trial-balance revenue, the elected deduction, the factor recomputed from the receipts rows and the rate, and fails against the stated figure -- proving the summary is derived from the workpapers rather than trusted as filed.
Functional block diagram
engineering · each block links to its sourcePlain terms
- Seeded Return Files. fictional combined-return files enter the control registry
- Structural Precondition. is the combined-return file complete and the review date legible
- Affiliate Register. is every affiliate unique, addressed, registered and in standing
- Combined-Group Roster. does the roster rebuild and is every exclusion reconciled
- Consolidated Trial Balance. is every revenue line well-formed, unique and attributable
- Receipts Apportionment. does the single receipts factor recompute and stay bounded
- Margin and Tax Derivation. does revenue tie the trial balance and the tax re-derive
- Return Rollup. does the determination recompute from the workpapers it summarises
- Workpapers & Margin Kernel. the artifacts and the one computation every rule resolves against
- Verdict and Findings. every finding, with the reason it exists, ends at a person
Engineering
- Seeded Return Files. generate_corpus writes one clean baseline plus one planted-defect file for every named control, twenty-three files in total. Only the affiliate register, the roster's prior-year members and this year's additions and removals, the consolidated trial-balance revenue lines, the receipts rows and the group's elected deduction and rate are stated as base facts; the current member list, the receipts totals and apportionment factor, group revenue, the taxable margin, the apportioned margin, the tax, the tax summary and the return totals are all re-derived through the same margin kernel the engine later recomputes with, so the relationships the engine tests are the relationships that produced the data.
- Structural Precondition. One control. FAILs a file missing any of the seven artifact types or carrying a duplicate of one, and FAILs an unreadable as_of date, so no downstream rule holds vacuously on absent evidence.
- Affiliate Register. Four controls: unique affiliate ids, a complete address and registration id on every row, a status inside the active / inactive vocabulary, and a FLAG on any registration renewing inside the file's own lead-time window measured to the as_of date.
- Combined-Group Roster. Three controls: the stated member list equals the prior year plus additions less removals, every member is an affiliate on the register, and every removal is enumerated on the excluded list with a reason and is not also a current member.
- Consolidated Trial Balance. Three controls: each line carries its id, affiliate, account and revenue figure; no line id repeats; and every line is attributed to a current combined member rather than to an affiliate outside the group.
- Receipts Apportionment. Four controls: in-state receipts never exceed everywhere receipts on a row, the stated totals sum those rows, the factor is in-state over everywhere floored to a basis point and bounded to [0.00%, 100.00%], and the margin worksheet applied that same recomputed factor.
- Margin and Tax Derivation. Four controls: group revenue sums the consolidated trial-balance lines, the taxable margin is revenue less the elected deduction clamped at zero, the apportioned margin is that margin at the recomputed receipts factor, and the tax is the apportioned margin at the margin-tax rate, each in truncating basis-point arithmetic compared with exact ==.
- Return Rollup. Two controls: the summarised tax is rebuilt end to end from the base facts -- trial-balance revenue, the elected deduction, the recomputed receipts factor and the rate -- and compared to the stated figure; and the return's total tax due and combined-member count tie the summary and the roster.
- Workpapers & Margin Kernel. The affiliate register carries each affiliate's address, registration id, status and renewal date; the combined-group workpaper carries prior-year members, additions, removals, the current member list and the excluded rows; the consolidated trial balance carries the revenue lines by affiliate; the receipts workpaper carries in-state and everywhere receipts by affiliate with the totals and the factor; the margin worksheet carries group revenue, the elected deduction, the taxable margin, the applied factor, the apportioned margin, the rate and the tax; and the tax summary and return rollup carry the determination and the filed total. Every roster, tie-out, apportionment and re-derivation control resolves against these through the shared margin kernel, so a recomputed tax cannot disagree with the arithmetic that produced the data.
- Verdict and Findings. Findings roll up per combined-return file: any FAIL is FAIL, FLAGs without FAILs are REVIEW, clean is PASS. The CLI exit code is the verdict, so a pipeline can gate on it. Reports carry no timestamps or absolute paths, which is what makes the committed report diffable.
Instruction set
every public command| Command | Operation | Output | Exit | Artifacts |
|---|---|---|---|---|
python run.py | regenerate the seeded fictional corpus, run all twenty-one controls, write both reports | per-file verdicts and every actionable finding, then the overall verdict | 2 for the bundled corpus, which carries a planted defect for every control by design | franchise_report.json, franchise_report.md, samples/ |
python -m franchise_engine samples | analyze an existing folder of combined-return files without regenerating it | per-file verdicts and findings | 0 PASS / 1 REVIEW / 2 FAIL / 3 usage | none unless --json or --md is passed |
python -m franchise_engine samples --generate --quiet | regenerate the corpus and print only the overall verdict | a single verdict line | 0 PASS / 1 REVIEW / 2 FAIL / 3 usage | samples/ |
python -m pytest franchise_engine/tests -q | run the full test suite for this engine | 10344 passed | 0 when every test passes | none |
Benchmarks
measured demo results| Measure | Result |
|---|---|
| Engine tests10 | 10,344 tests collected live collection from the engine directory |
| Registered controls11 | 21 controls counted from the registry, not from documentation |
| Planted defects12 | 22 defect files every registered control has at least one file that trips it |
| Control coverage13 | 100 percent of controls with a planted defect no control ships without a file demonstrating it firing |
Control characteristics
engineeringPlain terms
The engine has no write path and therefore no autonomy to gate. It produces findings; a person decides whether a figure is carried onto the combined return and whether a registration or an exclusion is chased.
Engineering
Deterministic envelope. seeded fictional inputs, read-only operation, offline default mode.
Demo gate. FAIL on the bundled corpus, by design -- it carries a planted defect for every registered control
| Severity | Verdict | Action |
|---|---|---|
| No findings above PASS | PASS | carry the mechanically clean combined-return file into the documented sign-off and filing review |
| One or more FLAG, no FAIL | REVIEW | a human resolves each flag; an affiliate registration renewing inside the file's lead-time window lands here, current but due to be lodged |
| One or more FAIL | FAIL | the figure is not carried onto the return until the failing control is cleared -- a roster that does not rebuild, an unreconciled exclusion, a member with no registration, a base that does not tie the trial balance, a factor or a tax that does not recompute |
- Read-only: combined-return files are parsed and never written back, so the engine cannot introduce the break it reports.
- Integer cents throughout, compared with exact ==; there is no tolerance band on a tax figure, and a cent off the re-derivation is reported as a break.
- A money field that should be integer cents but is not produces an AMOUNT_INVALID finding contained to the one row it was read on, rather than being coerced into the number the engine is meant to audit.
- One margin kernel: the controls and the generator share the kernel in franchise_engine.franchise, so a re-derived tax cannot disagree with the data that produced it.
- The apportionment factor is recomputed from the receipts rows and floored to a basis point, bounded to [0.00%, 100.00%]; flooring can only understate the share the state may tax, never overstate it.
- Every registration-renewal test is measured to the as_of date carried in the file, never to the system clock, so the same file yields the same flags on any day.
- Deterministic and byte-stable: same inputs produce the same findings in the same order, with no timestamps or absolute paths in any output.
- Absent evidence is never a passing control; a missing artifact fails completeness rather than letting the controls that read it pass unread.
Operating limits
what it refuses to do- The engine never files a return, remits a tax, amends a workpaper, contacts a revenue authority, or writes to a source artifact. It reads the combined-return file and stops.14
- It reads the seven artifacts the combined return emits. It does not connect to a general ledger, a consolidation system, a registration registry or a filing portal.15
- It proves the roster rebuilds from the prior year plus additions less removals and that every exclusion is reconciled; it does not decide whether the group is correctly drawn under the state's combination and nexus rules. That judgment is a preparer's and a reviewer's.16
- It re-derives the tax at the elected deduction and the margin-tax rate the file carries, and apportions at the receipts factor those receipts produce; it does not decide whether that election, that rate, or the sourcing of a receipt to the filing state is correct.17
- It takes the trial balance and receipts records at face value: it confirms they foot, tie and re-derive, not that the revenue was earned or the receipts sourced as stated. All shipped data is fictional -- the combined group, the affiliates, the State of Marran and City of Kelder, the addresses and registrations are invented, and the fiscal year is set in a fictional future.18
See it run
control architecture
Integration
how to run itDistribution: public repository, MIT license.
- 1python -m pytest --collect-only -q -o addopts= (franchise-tax-automation/)
- 2len(franchise_engine.engine.REGISTRY)
- 3distinct rule-id prefixes in franchise_engine.engine.REGISTRY
- 4samples/*.json after python run.py
- 5len(franchise_engine.model.DOC_TYPES)
- 6franchise_engine/tests boundary tests on the cent and the basis point
- 7python run.py (franchise-tax-automation/); franchise_engine/tests planted-defect suite
- 8franchise_engine/generate.py DEFECTS roster_discontinuity / excluded_unreconciled
- 9franchise_engine/generate.py DEFECTS summary_recompute_break -> rpt_summary_recomputes
- 10python -m pytest --collect-only -q -o addopts= (franchise-tax-automation/)
- 11len(franchise_engine.engine.REGISTRY)
- 12len(franchise_engine.generate.DEFECTS)
- 13franchise_engine/tests: every registered rule has a planted defect
- 14franchise-tax-automation/README.md and franchise_engine read-only / determinism tests
- 15franchise_engine/model.py DOC_TYPES
- 16franchise_engine/engine.py grp_ family
- 17franchise_engine/engine.py apt_ and mgn_ families
- 18franchise_engine/generate.py
Show us where the hours go.
One conversation: you describe the work that consumes your team's month; we tell you plainly what this engine can take over, what it can't, and what a scoped first phase would cost. Your people keep approval authority.
Book a free consultation