fix(docx): avoid numbering generated letter paragraphs - #337
Open
duncanmcqueen wants to merge 1 commit into
Open
fix(docx): avoid numbering generated letter paragraphs#337duncanmcqueen wants to merge 1 commit into
duncanmcqueen wants to merge 1 commit into
Conversation
The DOCX generator configured legal numbering unconditionally and inferred a numbering level for every paragraph under a section heading, so ordinary demand-letter prose came out as "1. DEMAND FOR PAYMENT / 1.1 We represent the claimant. / (a) Payment is required...". Prompting alone could not fix it: the renderer numbered the output whether or not the model asked for numbering. - Numbering is now opt-in via an optional numberSections tool argument. Letters and other prose render unnumbered by default. - When requested, only section headings are numbered; body prose is not. - Explicit bullets keep Word bullet formatting, and manually typed prefixes like "1." stay literal text when automatic numbering is off. - Both the dispatcher and the renderer test `=== true`, so a missing, null, or malformed value cannot switch numbering on by accident. Adds DOCX XML regression tests that read word/document.xml (and word/numbering.xml for bullets) out of the generated bytes. Rebased onto main; no conflicts with the docx text-value work in Open-Legal-Products#328, whose numeric-text regression test still passes alongside these. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
duncanmcqueen
force-pushed
the
fix/generated-letter-numbering
branch
from
August 21, 2026 12:23
b1a46ae to
8baa552
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
numberSectionstool argumentProblem
The DOCX generator always configured legal numbering and inferred a numbering level for every paragraph beneath a section heading. This caused ordinary demand-letter prose to render approximately as:
1. DEMAND FOR PAYMENT1.1 We represent the claimant.(a) Payment is required within ten days.A prompt-only fix would be insufficient because the renderer itself applied numbering even when the model did not request it.
Behavior after this change
Documents are unnumbered by default.
numberSections: truenumbers section headings when explicitly requested or required by a workflow/template, while ordinary prose remains unnumbered. Explicit bullets use Word bullet formatting. Manually typed prefixes such as1. This reference is intentional.remain literal text when automatic numbering is off.The dispatcher and renderer both use
=== true, so missing, null, string, or otherwise malformed values cannot enable numbering accidentally.Tests
New regression tests inspect
word/document.xml(andword/numbering.xmlfor bullets) inside generated DOCX bytes and cover:Validation completed (rebased onto current
main):tsc --noEmitinbackend— cleannpm testinbackend— 711 passed, 24 skippeddocumentGeneration.test.tscases all passRebased onto current main
Re-verified the bug has not been addressed upstream in the meantime:
documentOps.tsonmainstill callslegalNumbering(inferredLevel)for inferred paragraphs and still configures the numbering set unconditionally, andnumberSectionsappears nowhere inbackend/src.The rebase was clean. Worth noting explicitly because it touches neighbouring code: this does not conflict with the docx text-value work merged in #328 — that PR's
preserves numeric-looking text through an unrelated editregression test still passes alongside the new numbering tests.No database, frontend, provider, PDF reconstruction, or product-module changes are included.