# Chapter 6 — Output Contracts

> Define deliverable structure and test its figures, provenance and record-to-number bindings.

*Felix Reyes · The Skills Pack · First edition, 2026 · [CC BY 4.0](../LICENSE) · [Router](../SKILL.md)*

<a id="ch-contracts"></a>

Chapter [5](05-scripts-references-and-assets.md#ch-scripts) ended with a skill that runs its script, reads the display block and writes a note in five parts. The skill file lists the parts and leaves open how long each is and which figures it contains, so two runs can write two different notes and no program can say whether either has the shape it should. This chapter fixes the note’s shape. It is step 5 of the ten steps, Write the output contract, and the first half of step 6, Prove the skill: the three checks that read the deliverable itself.

Chapter [9](09-testing.md#ch-testing) completes step 6. Every demonstration here is deterministic: a note, written by hand or saved from a run, is checked beside the script’s output by the pack’s `tests/checks.py`.

## Why a contract

<a id="sec-contracts-why"></a>

Once a note has a fixed shape, a program can answer most of the question whether it is right: whether the sections are there, in order, whether every figure is one the script printed and, with the binding check of Section [6.8](06-output-contracts.md#sec-contracts-binding), whether a figure that belongs to one name is beside that name. The reviewer reads for the rest, which Section [9.1](09-testing.md#sec-testing-reading) lists. An *output contract* is the part of a skill file that fixes the deliverable’s shape: the sections it has and their order, what each section contains, which figures it may contain, and what it says when data is missing. Every figure it allows is a display string copied exactly as printed, including the parentheses.

Chapter [1](01-a-tutorial-introduction.md#ch-tutorial) printed the revenue bridge’s contract (Section [1.5](01-a-tutorial-introduction.md#sec-tutorial-contract)); the pack ships it as the last part of the leaf’s skill file, `skills/revenue-bridge/SKILL.md` lines 37 to 66, with one clause added: the script prints `n/a` when prior-year revenue is zero (Section [6.4](06-output-contracts.md#sec-contracts-missing)). The contracts of fifteen of the sixteen leaves in the four packs have the same parts, and the deck leaf’s is the exception.

A *section* is a level-2 heading and the lines under it, and each heading in a contract’s indented block is the literal line the note must contain.

In the sort sheet’s terms (Chapter [3](03-sorting-the-work.md#ch-sorting)), a contract’s sections and table rows are a house rule for one deliverable. The bullets that end the contract are its judgment rows, each with its bound. The sheet’s proof rows become the three checks that read the note back. A contract also gives the deliverable one shape whoever prepares it, which is what lets Chapter [10](10-rolling-out-across-an-organization.md#ch-rollout) compare different preparers’ notes section by section against the baseline.

## Fixed structure

<a id="sec-contracts-structure"></a>

The draft of Chapter [5](05-scripts-references-and-assets.md#ch-scripts) fixed none of this. The pack’s leaf ends with its contract:

File: `packs/variance-bridge/skills/budget-vs-actual/SKILL.md` (lines 60–63).

```markdown
## Output contract

The note has exactly these five sections, in this order:
```

File: `packs/variance-bridge/skills/budget-vs-actual/SKILL.md` (lines 64–68).

```markdown
    ## Headline
    One sentence: year-to-date revenue against budget and operating income
    against budget, each with its variance and variance percentage, from
    `display.ytd.subtotals`.
```

File: `packs/variance-bridge/skills/budget-vs-actual/SKILL.md` (lines 69–75).

```markdown
    ## Results
    A table with columns Measure, Actual, Budget and Variance, and these
    rows in this order, from `display.ytd.subtotals`: Revenue, COGS, Gross
    profit, Gross margin, Operating expenses, Operating income. The Gross
    margin row shows percentages, and its Variance is the points string,
    which ends in pts.
```

File: `packs/variance-bridge/skills/budget-vs-actual/SKILL.md` (lines 76–80).

```markdown
    ## Month
    One to three sentences on the month's revenue and operating income
    against budget, from `display.month.subtotals`. The first sentence
    starts with `display.labels.period_name`, month and year.
```

File: `packs/variance-bridge/skills/budget-vs-actual/SKILL.md` (lines 81–93).

```markdown
    ## Drivers
    Two to four bullets. Each names one line from `display.movers` with its
    year-to-date variance; or the months in `display.monthly_revenue` where
    the revenue miss concentrated, with their variances; or a line whose
    `display.peaks` entry shows a variance that reversed, with the peak and
    its month.

    ## Data notes
    One line in this form, with the backticks, where <file>, <rows> and
    <sha12> are the strings in display.input:
    <file>, <rows> rows, sha256 `<sha12>`
    Then display.rounding, after a blank line, when it is not empty.
```

File: `packs/variance-bridge/skills/budget-vs-actual/SKILL.md` (lines 94–103).

```markdown
- Copy every figure exactly as it appears in `display`, including parentheses.
- Display figures are rounded. Never add them up, subtract them or derive
  new figures from them, and never add up months.
- You choose which movers matter, their order, and what to ask each line
  owner. Call a variance timing only when `display.monthly_revenue` or
  `display.peaks` shows the reversal. Do not name a cause the data does not
  show.
- The Results table's COGS row is the COGS category: Cost of goods sold
  plus Freight out. In prose, name a line by its `line_item` in full
  ("Cost of goods sold"), and keep "COGS" for the category row.
```

This chapter’s three checks compare a whole note with its contract (Figure [6.1](06-output-contracts.md#fig-contract-check)).

**Figure — text equivalent.**

The contract requires four sections, in order and exactly once: Headline (one sentence containing CY, PY, change and percent); Bridge (seven rows whose amounts equal the display block); Drivers (two to four bullets); Data notes (file, rows and the first twelve SHA-256 characters). Provenance permits display strings and the hash: `$11,238K`, `($1,288K)`, `4`, and `742a2059e0fd` pass the illustrated token gate; `$9.9M` was not printed by the script. Binding also checks the name beside a figure: `($686K)` belongs to Fenwick Legal, so that name/amount pairing passes; Birchway Foods paired with `($686K)` fails.

<a id="fig-contract-check"></a>

The three checks on the revenue bridge’s note. The contract check compares the sections with their order and rules, the provenance check passes only figures the script printed, and the binding check passes a figure that belongs to one name only beside that name.

Five kinds of rule fix the structure. A section list gives the sections by name, in order, exactly once each. The contract check takes every line that starts with two hashes and a space, lowercases the name and compares the list with the contract’s. A renamed, missing, duplicated, extra or misplaced section fails that one comparison.

A table rule gives named columns and named rows in order. A row label is a fixed word (Revenue, COGS) or a label the script printed (FY2024 in the revenue bridge). Every other cell is a display string.

A bounded list has two ends. In “two to four bullets” the lower end makes the section say something and the upper keeps it a summary. Write bounds a check can count, since “a few bullets” gives it nothing to count. A sentence count is a structure rule in the same way: one sentence for the Headline, one to three for Month. A fixed line puts the data notes in a set form, with the three strings of `display.input` in their places, then `display.rounding` when it is not empty. The check looks for the three strings, with the hash in backticks, and for the rounding sentence, and leaves the wording of the line to the reviewer.

**Exercise 6-1.** Make a run folder containing `data/pnl_fy2025.csv`, the script’s `output/bva.json`, and the pack’s good budget-vs-actual fixture from `tests/fixtures/` saved as `output/bva-note.md`, its `{sha12}` placeholder replaced by `display.input.sha12`. Run `tests/checks.py` on it with the case `tests/cases/budget-vs-actual-fy25.json`. Then rename `## Month` in a copy and read the contract’s detail line. Then give the Month section four sentences and read it again.

## Required figures and where they come from

<a id="sec-contracts-figures"></a>

A contract gives, for every figure the note must contain, the display key it is copied from. A *display key* is the dotted path of a string under `display`: the string at `display.ytd.subtotals.revenue.variance` is `($362K)`. The budget-vs-actual script mirrors its exact blocks under `display` with the same keys, while the display block of `bridge.py` is flat.

Table [6.1](06-output-contracts.md#tab-contracts-slots-bva) is the budget-vs-actual contract as a worksheet (Appendix [C](appendix-c-worksheets-and-test-kit.md#app-worksheets) has the blank form). Each row is a *slot*, a place in the note where one figure goes.

<a id="tab-contracts-slots-bva"></a>

The budget-vs-actual contract as a worksheet. Keys are under `display`; `[]` is each item of a list; `<measure>` is `revenue`, `cogs`, `gross_profit`, `gross_margin_pct`, `opex` or `operating_income`. C, P and B are the contract, provenance and binding checks; reader is the reviewer.

| Slot | Display key | Golden string | Checked by |
| --- | --- | --- | --- |
| *Headline: one sentence* |  |  |  |
| Revenue variance, % | `ytd.subtotals.revenue.variance`, `.variance_pct` | `($362K)`, `(3.1%)` | C, P |
| Operating income variance, % | `ytd.subtotals.operating_income.variance`, `.variance_pct` | `($195K)`, `(33.5%)` | C, P |
| *Results: six rows, Revenue to Operating income, in order* |  |  |  |
| Actual, Budget, Variance | `ytd.subtotals.<measure>.actual`, `.budget`, `.variance` | `$11,238K`, `$11,600K`, `($362K)` | C, P |
| Gross margin Variance | `ytd.subtotals.gross_margin_pct.variance` | `(0.9) pts` | C, P |
| *Month: one to three sentences* |  |  |  |
| Period name | `labels.period_name` | `December 2025` | C, reader |
| Revenue | `month.subtotals.revenue.actual`, `.budget`, `.variance` | `$827K`, `$824K`, `$3K` | P, B, reader |
| Operating income | `month.subtotals.operating_income.actual`, `.budget`, `.variance` | `$8K`, `$13K`, `($5K)` | P, B, reader |
| *Drivers: two to four bullets, counted by C* |  |  |  |
| A cost mover | `movers.unfavourable[].variance` (or `favourable`) | `($38K)` | P, B, reader |
| A revenue month | `monthly_revenue[].variance`, `.period` | `($123K)`, `2025-03` | P, B, reader |
| A reversal | `peaks[].variance`, `.period` | `($31K)`, `2025-03` | P, B, reader |
| *Data notes: one line, then the sentence in `rounding`, if any (C)* |  |  |  |
| File, rows, hash | `input.file`, `.rows`, `.sha12` | `pnl_fy2025.csv`, `120`, `eaa52ac89e97` | C, P, reader |

The last column matters as much as the key. In the Month section the contract check asks only that `labels.period_name` appears somewhere, and provenance asks of a figure only whether the script printed it, so a Month sentence that gave the year’s COGS, `$8,324K`, as the month’s revenue passes both. Section [6.8](06-output-contracts.md#sec-contracts-binding) adds the check that fails it, the one the B marks stand for. A reviewer looks at every slot marked “reader” in every note. The revenue bridge’s contract fills the same worksheet in five rows (`answers/ch06.md`), its row labels taken from the result’s `labels` block.

Display figures are rounded, so the contract forbids adding them up or deriving a new figure from them (Section [6.7](06-output-contracts.md#sec-contracts-provenance) catches a sum). Re-expression is the quieter fault: the upsell, `$1,211K`, written as `$1.2M` or `1.21 million` is the same movement in a string the script did not print, and the provenance check flags it.

When a reader needs a figure the script does not print, change the script and keep the rule: `display.peaks` is there for a variance that reversed during the year (Section [3.4](03-sorting-the-work.md#sec-sorting-bva)).

**Exercise 6-2.** In a copy of the good revenue-bridge note, `examples/ch06/fixtures/bridge-note-good.md`, change the Upsell row’s amount to another figure in the right format: first one the script printed for a different row, then one it never printed. Which check catches each, and would the other?

**Exercise 6-3.** Add a Drivers bullet to the good revenue-bridge note that is arithmetically true and sums two display figures, for example upsell and new. Run the provenance check. Explain why the contract forbids the bullet even though its figure is correct.

## Missing data

<a id="sec-contracts-missing"></a>

A contract says what the note contains when an input is absent or a figure is undefined. The answer is a string the script printed, or no note at all. Budget-vs-actual meets three cases.

A column is missing. Step 1 of the leaf opens only the CSV’s header row and asks for a file with all five columns before anything runs. A script run on such a file anyway exits 2 with the message Table [5.1](05-scripts-references-and-assets.md#tab-scripts-exit-codes) prints, and step 3 shows it and stops. Either way no note is written.

A figure is undefined. A variance percentage divides by the budget, and a line budgeted at zero has no percentage, so the script prints the string `n/a` in its place. Here is the script on a copy of `pnl_fy2025.csv` with Other operating’s budget set to `0.00` in all twelve months, then the first unfavourable mover in its display block:

File: `examples/ch06/outputs/bva-zero-budget.txt` (lines 1–3).

```text
$ python3 packs/variance-bridge/skills/budget-vs-actual/scripts/bva.py --input examples/ch06/fixtures/pnl-zero-budget.csv --output /tmp/run/output/bva.json
YTD 2025 revenue $11,238K vs budget $11,600K, variance ($362K); operating income $388K vs $703K, variance ($315K); reconciles. Wrote /tmp/run/output/bva.json
exit 0
```

File: `examples/ch06/outputs/bva-zero-budget.txt` (lines 16–21).

```text
$ python3 -c "import json; d = json.load(open('/tmp/run/output/bva.json'))['display']; print(json.dumps(d['movers']['unfavourable'][0], indent=2))"
{
  "line_item": "Other operating",
  "variance": "($120K)",
  "variance_pct": "n/a"
}
```

The line is now the largest unfavourable mover, so a Drivers bullet on it has `n/a` where the percentage would go, copied as printed. The provenance check never sees `n/a`, which is not a figure token (Section [6.7](06-output-contracts.md#sec-contracts-provenance)). The contract’s first rule, copy every figure exactly as it appears in `display`, covers it.

The revenue bridge has the same case. A customer file whose prior-year total is zero has no percentage change, and `bridge.py` prints `n/a` for `display.change_pct` rather than `0%`. The Headline copies the string, and the contract’s Headline line says so.

A contract whose table always has an undefined cell says so in words. The scenario memo of Chapter [11](11-four-complete-packs.md#ch-complete) compares each scenario with the base, and the base row has nothing to compare with, so its contract ends the table’s description with “The base row’s last two cells are n/a, as display prints them.”

A period is not in the file. The script exits 2 with the message Table [5.1](05-scripts-references-and-assets.md#tab-scripts-exit-codes) prints, naming the range the file covers, and step 3 shows it and stops. A note on the last month in the file would answer a question nobody asked.

A list in the display block can be empty, and the contract says what the section contains then. The flux analysis of Chapter [11](11-four-complete-packs.md#ch-complete) allows an empty Below threshold section and says so: zero to three bullets, and the check’s lower bound is zero. The close checklist has one Exceptions bullet per violation and per missing piece of evidence, and “When both lists are empty, one bullet that says so.” Its check then expects exactly one bullet. A contract that says nothing leaves the model to choose between an empty section and a line of filler, and gives the check no rule to apply to either.

## Phrasing rules

<a id="sec-contracts-phrasing"></a>

A *phrasing rule* says how something in the note is written rather than where it goes. A rule for every deliverable the company writes belongs in a house skill, the executive voice that Chapter [8](08-the-shared-layer.md#ch-shared) prints and audits rule by rule. A rule about one leaf’s figures and words goes in that leaf, in its contract, its step 6 or its account of the display block. Budget-vs-actual’s sign rule is in the last of these: “Use only the words favourable and unfavourable for the sign.”

A rule no check enforces is left to the reviewer. Table [6.2](06-output-contracts.md#tab-contracts-checkable) lists the two leaves’ phrasing rules and what checks each.

<a id="tab-contracts-checkable"></a>

Phrasing rules in the revenue-bridge (RB) and budget-vs-actual (BvA) leaves, and what checks each.

| Rule | Where | Checked by |
| --- | --- | --- |
| Copy every figure as `display` prints it | Both contracts | provenance; contract |
| Never put a positive figure in parentheses | Both, step 6 | provenance (a figure alone); binding (a string another line owns); reviewer (asides) |
| Only “favourable” and “unfavourable” for the sign | BvA | reviewer |
| A verb joins name and figure; “or” joins a percentage | Both, step 6 | reviewer |
| A Drivers bullet names a mover or a movement total | RB contract | reviewer |
| Say timing only when the display block shows it | BvA contract | reviewer |
| Keep “COGS” for the category row; name a line in full | BvA contract | binding (a line’s figure beside COGS); reviewer |
| Name no cause the data does not show | Both contracts | reviewer |

The parentheses row is checked only in part, because the provenance check keeps parentheses on a token only when they open and close it. In the good budget-vs-actual note, a bullet that adds Technology’s favourable `$25K` as `($25K)` fails: the script printed no such string. Marketing’s favourable `$38K` written as `($38K)` passes provenance, because the script printed `($38K)` for Salaries and wages. The binding check of Section [6.8](06-output-contracts.md#sec-contracts-binding) fails it, because `($38K)` belongs to that line. An aside, “(favourable by \$38K, or 28.5%)”, yields the tokens `$38K` and `28.5%`, both printed and both Marketing’s, and passes every check.

**Exercise 6-4.** For each row of Table [6.2](06-output-contracts.md#tab-contracts-checkable) marked reviewer, say whether a program could check it, and how, or why only a reader can.

## The contract check

<a id="sec-contracts-check"></a>

The *contract check* compares a deliverable with its leaf’s output contract. It is one function for every leaf in every pack: `contract` looks up the leaf’s entry in the pack’s `SKILLS` table and passes the entry, the note’s text and the script’s result to `_check_contract`. Both functions are in the generic core of `tests/checks.py`, which is identical in every pack (Section [9.2](09-testing.md#sec-testing-scope)). A pack supplies only the entry, or a function of its own for a deliverable that is not a Markdown note, as the deck leaf does (Chapter [11](11-four-complete-packs.md#ch-complete)).

The entry is the *contract specification*, the contract rewritten as data. Here is the revenue bridge’s, as far as its contract goes. The entry continues with the leaf’s binding and header specifications (Section [6.8](06-output-contracts.md#sec-contracts-binding), Chapter [10](10-rolling-out-across-an-organization.md#ch-rollout)):

File: `packs/variance-bridge/tests/checks.py` (lines 937–941).

```python
    "revenue-bridge": {
        "identity": Identity(rb_from_result, rb_from_source),
        "contract": {
            "sections": ["headline", "bridge", "drivers", "data notes"],
            "sentences": {"headline": (1, 1)},
```

File: `packs/variance-bridge/tests/checks.py` (lines 942–949).

```python
            "contains": {"headline": ["cy", "py", "change", "change_pct"], "data notes": rounding_note},
            "tables": {"bridge": {"columns": ["Step", "Amount"],
                                  "rows": [("labels.py", "", ["py"]), ("Timing", "", ["timing"]), ("Loss", "", ["loss"]),
                                           ("Decline", "", ["decline"]), ("Upsell", "", ["upsell"]), ("New", "", ["new"]),
                                           ("labels.cy", "", ["cy"])]}},
            "bullets": {"drivers": (2, 4)},
            "data_notes": True,
        },
```

Read it beside the contract Chapter [1](01-a-tutorial-introduction.md#ch-tutorial) printed. `contains` lists what the Headline and the Data notes must quote: `"cy"` is `display.cy`, and `rounding_note` the rounding sentence. Each table row is a label, a base path and the fields that fill its cells. The base path is empty because this display block is flat, and `labels.py` takes the label from the result’s `labels`.

`_check_contract` applies a specification in a fixed order, and its docstring lists every key a specification may contain. The section list comes first, because every later rule looks a section up by name, and the first rule that fails ends the check with a detail line naming the section and what was expected. A table goes through `_check_table`, which compares the header with the columns, the first cells with the row labels in order and every other cell with its display string, and allows a unit word such as `pts` after it.

Here are the contract check’s lines in the output for the good revenue-bridge note with `## Drivers` renamed `## Why`:

File: `examples/ch06/outputs/contract-missing-section.txt` (lines 15–18).

```text
  "contract": {
    "passed": false,
    "detail": "sections are ['headline', 'bridge', 'why', 'data notes'], expected ['headline', 'bridge', 'drivers', 'data notes'] exactly once each"
  },
```

The detail line prints both lists, so the finding is plain without opening the note. Provenance passes the same note, because every figure in it is still a display string. Change the Upsell row’s `$1,211K` to `$1,121K` instead and both fail: the contract check reports the row, what it found and what it expected, and the provenance check reports `$1,121K`, which is not a display string.

**Exercise 6-5.** Does a nested bullet count toward “two to four”? Read `_bullets` in the generic core and predict the answer. Then give one Drivers bullet of the good revenue-bridge note two indented sub-bullets and run the checks. Then delete the other two top-level bullets and run them again.

## The provenance check: a figure allowlist

<a id="sec-contracts-provenance"></a>

The *provenance check* asks one question of every figure in the note: is it in the set of strings the script printed? It is an allowlist of figure tokens. It ignores the words around a figure, so it cannot know which customer, line, period or sign a figure belongs to. That is the binding check’s work (Section [6.8](06-output-contracts.md#sec-contracts-binding)). What it does catch depends on what counts as a figure.

The generic core defines a figure with one regular expression:

File: `packs/variance-bridge/tests/checks.py` (lines 82–84).

```python
FIGURE = re.compile(
    r"(?<![A-Za-z0-9.\-_])\(?[-\u2212]?\$?(?:\d(?:,?\d)*(?:\.\d+)?|\.\d+)[A-Za-z0-9%]*\)?(?![A-Za-z0-9])"
)
```

<a id="tab-contracts-tokens"></a>

The tokenizer’s test cases: a line of a note and the figure tokens `figures_in` finds in it.

| Line | Figure tokens |
| --- | --- |
| `Petty cash moved $250, or 62.5%.` | `$250`, `62.5%` |
| `In 9+3, closed months were 3.` | `9`, `3`, `3` |
| `Customer IS-012 is a name.` | none |
| `File customers_fy24 is a name.` | none |
| `Gross margin fell (1.2) pts.` | `(1.2)` |
| `Revenue of $11,243,300.00 and 1,234 units.` | `$11,243,300.00`, `1,234` |
| `FY2024, 2025-12 and WD+3.` | `3` |
| `1. First driver: $53K.` | `$53K` |
| `Hash 742a2059e0fd and code $9.9M.` | `742a2059e0fd`, `$9.9M` |

A *figure token* starts with a digit, a dollar sign, a minus sign, an opening parenthesis or a decimal point, and runs to the end of the word, so `3x`, `120bps` and `$999k` are figure tokens. A comma belongs to a figure only between digits. A token glued to a letter, a digit, a dot, a hyphen or `_` before it is a name, so `FY2024`, `IS-012` and `customers_fy24` yield none.

`figures_in` applies the expression to the whole note, including fenced code, after removing backticks and the one- or two-digit list marker at the start of a line, and skips a bare year, four digits starting `19` or `20`, so “December 2025” and “2025-03” yield nothing. Table [6.3](06-output-contracts.md#tab-contracts-tokens) gives the cases the repository’s tests run the tokenizer against, in every pack.

Then `provenance`, the function Chapter [1](01-a-tutorial-introduction.md#ch-tutorial) printed from the stage’s copy of the core, looks up every token in a set of allowed figures.

The set contains every display string, every figure token inside one (so the forecast-accuracy version label `3+9` allows `3` and `9`), and every input’s full hash and its first 12 characters (Appendix [A](appendix-a-reference-manual.md#app-reference), 6.1.3). `_normalize` runs on both sides: it turns a Unicode minus into a hyphen and strips any parenthesis that does not pair with one at the other end of the token, so `($1,288K)` must match a display string parentheses and all, while the `)` that closes an aside drops away (Section [6.5](06-output-contracts.md#sec-contracts-phrasing)). The detail line lists every token outside the set.

Of the five tokens in Figure [6.1](06-output-contracts.md#fig-contract-check), four are display strings or the hash. The fifth, `$9.9M` in the bullet Chapter [1](01-a-tutorial-introduction.md#ch-tutorial) planted, is not, and the note fails as it did there.

A derived figure fails the same way. This copy of the good note replaces “offset most of the loss” with a figure of its own:

File: `examples/ch06/fixtures/bridge-note-derived-sum.md` (lines 20–20).

```markdown
- Upsell of $1,211K from 23 customers netting to ($78K) with losses; Harbor Freight Partners added $148K.
```

File: `examples/ch06/outputs/provenance-derived-sum.txt` (lines 19–22).

```text
  "provenance": {
    "passed": false,
    "detail": "figures not printed by the script: ['($78K)']"
  },
```

`($78K)` is the exact upsell plus the exact loss, rounded. The arithmetic is right and the figure is still forbidden: nothing ties it to the input, and a reader cannot tell whether it came from the exact totals or from two rounded strings, which here add to a different figure.

The good note passes all six checks, and its provenance detail, “all 22 figures trace to the script’s display block”, counts every figure token in the note, counting repeats. The budget-vs-actual fixture passes with 42.

**Exercise 6-6.** Write the price-volume-mix leaf’s output contract as a worksheet like Table [6.1](06-output-contracts.md#tab-contracts-slots-bva), from its skill file alone, then compare it with the leaf’s entry in `SKILLS`.

**Exercise 6-7.** Design the contract and provenance checks for the KPI scorecard of the Management Reporting pack. Which display keys must the note quote, and where? What does the provenance check allow when the script reads two inputs? What could an independent check recompute from `kpis_fy2025.csv` and `pnl_fy2025.csv` without the script? Compare your design with the leaf’s `SKILLS` entry.

## The binding check

<a id="sec-contracts-binding"></a>

The *binding check* reads what the provenance check ignores: the words beside a figure. Here is the Month sentence of Section [6.3](06-output-contracts.md#sec-contracts-figures), in the good budget-vs-actual fixture with one figure changed:

File: `examples/binding/fixtures/bva-note-cogs-as-revenue.md` (lines 16–18).

```markdown
## Month

December 2025 revenue was $8,324K against a budget of $824K, a favourable $3K. Operating income was $8K against $13K, an unfavourable ($5K).
```

Every figure in it is a display string, and five checks pass it. The provenance and binding entries:

File: `examples/binding/outputs/bva-cogs-as-revenue.txt` (lines 24–31).

```text
  "provenance": {
    "passed": true,
    "detail": "all 42 figures trace to the script's display block"
  },
  "binding": {
    "passed": false,
    "detail": "$8,324K belongs to COGS (records), which this sentence in month does not name: 'December 2025 revenue was $8,324K against a budget of $824K, a favourable $3K.'; $8,324K belongs to YTD 2025 (scopes), which this sentence in month does not name: 'December 2025 revenue was $8,324K against a budget of $824K, a favourable $3K.'"
  }
```

`$8,324K` is the COGS row’s actual in the year’s subtotals, so it belongs to the record COGS and to the scope YTD 2025, and the sentence names neither. A revenue-bridge bullet fails the same way. This copy of the good note gives Fenwick Legal’s loss to Birchway Foods:

File: `examples/binding/fixtures/bridge-note-swapped.md` (lines 19–19).

```markdown
- Losses of ($1,288K) across 4 customers, led by Birchway Foods at ($686K).
```

File: `examples/binding/outputs/revenue-bridge-swapped.txt` (lines 28–31).

```text
  "binding": {
    "passed": false,
    "detail": "($686K) belongs to Fenwick Legal (records), which this bullet in drivers does not name: 'Losses of ($1,288K) across 4 customers, led by Birchway Foods at ($686K).'"
  }
```

Provenance passes it: the note has the good note’s 22 figures, and one of them is beside a different name.

The display block puts every figure under a path, and the leaf’s `SKILLS` entry says which paths are *records* (a customer, a P&L line, a KPI, a version), which are *scopes* (the month against the year to date, a scenario), and what each is called. A figure that appears only under one record belongs to it. A figure two records share, or one under no record, belongs to nothing. Every bullet and sentence outside the headline, the tables and the data notes is free, and there a figure that belongs to one record must be in a bullet or sentence that names that record, and a figure that belongs to one scope must be beside its scope’s name. The section heading counts as part of the sentence, and so does a default the entry gives a section. Budget-vs-actual’s entry:

File: `packs/variance-bridge/tests/checks.py` (lines 973–982).

```python
        "binding": {
            "records": [Bind("month.lines.*", bva_line), Bind("ytd.lines.*", bva_line),
                        Bind("month.subtotals.*", P_AND_L), Bind("ytd.subtotals.*", P_AND_L),
                        Bind("monthly_revenue.*", ["Revenue"]), Bind("peaks.*", bva_line),
                        Bind("movers.*.*", bva_line)],
            "scopes": [Bind("month", bva_month), Bind("ytd", bva_ytd), Bind("movers", bva_ytd),
                       Bind("monthly_revenue.*", lambda x, k, d: period_names(x["period"])),
                       Bind("peaks.*", lambda x, k, d: period_names(x["period"]))],
            "sections": {"drivers": ["labels.ytd"]},  # the contract makes every driver a year-to-date variance
        },
```

`records` lists the P&L lines wherever they appear, by their `line_item` and the short names `BVA_LINES` adds (“freight” for Freight out, “salary” for Salaries and wages); the six subtotals by the Results table’s row labels; and the months of `monthly_revenue` as Revenue. `scopes` puts `month` in the month scope, which a sentence names with the word “month”, the period or the month’s name. It puts `ytd` and `movers` in the year scope, named by `labels.ytd`, “year to date” or “full year”. `sections` gives Drivers the year as its default, because the contract makes every driver a year-to-date variance. Names match as whole words in any case, plurals and possessives allowed.

In the edition’s repeat runs, at version 1.0.0, the first primary model wrote this note for the budget-vs-actual case. Here are the COGS row of its Results table and its second Drivers bullet:

File: `runs/20261004-0335-repeat-variance-bridge-claude-sonnet-5-5/budget-vs-actual-fy25/claude/r1/output/bva-note.md` (lines 8–8).

```markdown
| COGS | $8.3M | $8.5M | $167K |
```

File: `runs/20261004-0335-repeat-variance-bridge-claude-sonnet-5-5/budget-vs-actual-fy25/claude/r1/output/bva-note.md` (lines 19–19).

```markdown
- COGS was favourable by $196K, or 2.4%, while freight out was unfavourable by ($29K), or (8.3%). Freight out reached its peak variance of ($29K) in December, so it ran over budget through the year and did not reverse.
```

A reviewer reads the row first: COGS came in `$167K` under budget for the year. The bullet says COGS was favourable by `$196K`. `$196K` and `2.4%` are the Cost of goods sold line’s variance. The COGS row is that line and Freight out together, and the line’s `$196K` less Freight out’s `($29K)`, the figure the bullet gives to freight in its second clause, is the row’s `$167K`.

In the run’s record the contract check passed, five sections in order. Provenance passed with the detail “all 57 figures trace to the script’s display block”, because it reads each figure token against the display block and every figure in the bullet is there. Binding failed: `$196K belongs to Cost of goods sold (records), which this bullet in drivers does not name`, and the same line again for `2.4%`. In the note the two figures carry the same label, and the note says nowhere which is the line and which the row. Budget-vs-actual was held back at 1.0.0, and Chapter [10](10-rolling-out-across-an-organization.md#ch-rollout), Section [10.3](10-rolling-out-across-an-organization.md#sec-rollout-versions), says what the pack’s owner did about it.

Binding matches only names. A figure that belongs to two records passes beside either: `$25K` is Technology’s year-to-date variance and Freight out’s December budget, so a bullet that gives it to Marketing passes. A figure beside the right name with the wrong verb passes: “Marketing was unfavourable by \$38K” names Marketing. A cause the data does not show passes, and so does a sentence that is true and misleading. The display block already has the full association a stronger check would need (metric, entity, period, unit, value and source). Binding uses only the part a sentence can be matched against.

Binding knows only the names its entry lists, and a model has more words for a record than any list. Section [9.6](09-testing.md#sec-testing-the-checks) says what the runs taught the test kit.

**Exercise 6-8.** Write a Drivers bullet for the good budget-vs-actual note that is false and made only of display strings: give Marketing’s favourable `$38K` to Technology. Run the checks: which passes, which fails, and what does the binding detail line name? Then write a false bullet that every check passes, and say what a reviewer would need to catch it.
