Skip to content

Add deterministic conditional page injection to FormSpec generation #132

@danielnaab

Description

@danielnaab

Goal

As a person filling out a digitized form, I want pages that don't apply to me to be skipped automatically, so I don't waste time on irrelevant questions.

Context

Story #121 improved FormSpec layout quality by +19.8pp through a layout-aware extraction prompt. However, conditional page use (scoring pages as skippable based on user answers) improved only modestly (37.5% → 43.8%) despite explicit prompt instructions and worked examples.

The core difficulty: the LLM must derive page-level conditions from field-level conditions in the DataCollectionSpec. This requires:

  1. Identifying groups where most/all requirements share a common condition
  2. Separating the "gate" question (the field that triggers the condition) to a prior page
  3. Adding the correct condition JSON to the page

This inference is unreliable via prompt alone. A deterministic post-processing step would be more robust.

Scope

Implement a post-processing function that runs after FormSpec generation (Step 2) and adds condition properties to pages where appropriate:

  • Scan each page's groups for fields with shared conditions
  • If ≥80% of a group's non-gate fields share the same condition, lift it to the page level
  • Ensure the gate field is on a prior page (reorder if needed)
  • Validate the resulting FormSpec still passes schema checks

Acceptance Criteria

  • A addPageConditions(spec: DataCollectionSpec, formSpec: FormSpec) => FormSpec function exists
  • It correctly identifies and adds page-level conditions for at least 2 of the 4 test fixtures
  • Layout quality evaluation shows conditional use metric ≥ 62.5% (score 3.5+/5 average)
  • Existing tests continue to pass
  • The function is wired into the extraction pipeline as an optional post-processing step

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions