Skip to content

feat(form-documents): layout-aware FormSpec generation#134

Open
danielnaab wants to merge 12 commits intomainfrom
story-121/form-layout
Open

feat(form-documents): layout-aware FormSpec generation#134
danielnaab wants to merge 12 commits intomainfrom
story-121/form-layout

Conversation

@danielnaab
Copy link
Copy Markdown
Member

Summary

  • Adds a civic-tech-informed layout prompt that produces well-structured multi-page FormSpecs from government form PDFs (+19.8pp quality improvement over baseline)
  • Introduces an LLM-as-judge layout quality evaluation kind with 6-dimension rubric (page sizing, topic cohesion, logical progression, conditional use, title clarity, delivery mode)
  • Registers sonnet-hybrid-layout-v1 extractor variant and evaluate layout CLI command for measuring layout quality

Story

Closes #121

Acceptance Criteria

  • An audit of current form output identifies specific issues with examples
  • Forms with more than ~10 fields are broken into logical sections or multi-step flows
  • Related fields are grouped with descriptive section headings
  • The form layout works well on mobile viewports (confirmed by existing renderer)
  • Accessibility review confirms screen reader compatibility (existing fieldset/legend/ARIA structure)
  • At least one real-world form tested end-to-end through the improved pipeline (4 fixtures tested)

Test Plan

  • bun test passes (1369 tests, 0 failures)
  • Type check passes (tsc --noEmit)
  • Lint passes on changed files
  • Layout evaluation run against all 4 fixtures (W-9, I-9, SNAP Wisconsin, Pardon Application)
  • Baseline vs variant comparison shows improvement across dimensions

Review Notes

  • The variant does NOT become the production default — it's registered as experimental for comparison. Promotion decision is documented in findings.
  • Conditional page use improved modestly (37.5% → 43.8%) but hit a prompt-difficulty ceiling. Follow-up filed as Add deterministic conditional page injection to FormSpec generation #132 for deterministic post-processing.
  • Pre-existing biome warnings (84) exist in files not touched by this PR.
  • The dist/styles.css test error is pre-existing (build artifact not present in worktree).

danielnaab added 12 commits May 6, 2026 07:24
The formSpecSchema requires these fields. Also commits baseline and
layout variant evaluation results showing +17.7% overall improvement.
Documents methodology, per-fixture results, and recommendations.
Key finding: +17.7pp overall improvement with largest gains in title
clarity (+43.7pp), topic cohesion (+37.5pp), and page sizing (+31.3pp).
Conditional page use and delivery mode identified as areas for iteration.
…ance

Delivery mode: removed overly conservative "default to static" and
replaced with content-complexity-based criteria (narrative fields,
sensitive topics, eligibility logic → conversational).

Conditional pages: added explicit instructions for deriving page-level
conditions from field-level conditions, with a worked example in the
schema. Modest improvement (+6.3pp) but the inference remains hard for
a prompt-only approach.

Results: overall 77.1% (+19.8pp vs baseline). Delivery mode regression
eliminated. Conditional use improved from 37.5% to 43.8%.
Final results after prompt iteration: +19.8pp overall (57.3% → 77.1%).
Delivery mode regression eliminated. Conditional page use improved
modestly (+6.3pp) but confirmed as a prompt-difficulty ceiling.
Follow-up filed as #132 for deterministic post-processing approach.
Replace module-level mutable state (setLayoutJudge) with a factory
function (createLayoutQualityKind) that takes the judge as a parameter.
Consistent with the existing createLlmJudgeKind pattern.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize generated form layout to follow best practices

1 participant