Skip to content

[FEAT]: Validation gates input extraction json pdf#279

Open
Aryama-srivastav wants to merge 4 commits intofireform-core:mainfrom
Aryama-srivastav:feature/validation-gates-input-extraction-json-pdf
Open

[FEAT]: Validation gates input extraction json pdf#279
Aryama-srivastav wants to merge 4 commits intofireform-core:mainfrom
Aryama-srivastav:feature/validation-gates-input-extraction-json-pdf

Conversation

@Aryama-srivastav
Copy link

Description

Implemented three-stage validation checkpoints in the form-filling pipeline to improve measurable robustness before production.

What changed

  1. Added validation_gates.py with:
  • GateResult (pass/fail + reason codes + details)
  • ValidationReport (run summary with overall pass/fail and JSON export)
  • ValidationGates: input_to_extraction(...), extraction_to_json(...), json_to_pdf(...)
  1. Integrated gates into filler.py :
  • Runs all 3 gates per fill run
  • Generates per-run validation report JSON
  • Blocks final PDF output when strict_validation=True and any gate fails
  1. Added tests: tests/test_validation_gates.py

Acceptance criteria mapping

✅ Each gate returns pass/fail + reason codes.
✅ Completeness and mandatory field checks enforced.
✅ Mismatch/misplacement surfaced before final output (PDF_FIELDS_UNMATCHED, POSITIONAL_FALLBACK_USED, etc.).
✅ Summary validation report generated per run.

How to test

  1. Run:
  • python -m pytest -q tests/test_validation_gates.py
  1. Execute normal fill flow and verify:
  • validation report JSON is written per run
  • strict mode blocks PDF write on failed gate(s)

Copilot AI review requested due to automatic review settings March 17, 2026 16:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a validation “gating” layer to the PDF form-filling pipeline to detect common failure modes (bad inputs, incomplete extraction, mapping mismatches) and optionally block PDF generation in strict mode.

Changes:

  • Introduces validation_gates.py (gate results + run report + 3 validation stages).
  • Adds a new semantic mapping layer (semantic_mapper.py) and integrates gates + report output into filler.py.
  • Adds unit tests for validation gates and semantic mapper behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/validation_gates.py Implements gate results/reporting and the 3-stage validation checks.
src/filler.py Runs the gates during fill, writes a per-run validation report, and blocks output in strict mode.
src/semantic_mapper.py Adds semantic matching (explicit/case-insensitive/alias/fuzzy) with positional fallback and reporting.
tests/test_validation_gates.py Tests gate pass/fail and reason codes for each stage.
src/test/test_semantic_mapper.py Tests semantic mapper matching modes, fallback behavior, and report formatting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +120 to +123
unmatched_pdf_fields = [f for f in pdf_field_names if f not in matched]
required_pdf_fields: list[str] = template_config.get("required_pdf_fields", []) if template_config else []
missing_required_pdf = [f for f in required_pdf_fields if f not in matched]

Comment on lines +1 to +4
from types import SimpleNamespace

from src.validation_gates import ValidationGates

Comment on lines +18 to +20
def test_input_to_extraction_fail_missing_pdf_and_bad_extraction():
gate = ValidationGates.input_to_extraction(
"C:/does-not-exist/form.pdf",
@@ -0,0 +1,113 @@
from src.semantic_mapper import SemanticMapper, MappingResult
Comment on lines +43 to +45
t2j = llm.main_loop()
textbox_answers = t2j.get_data() # {json_key: value}

Comment on lines +70 to +73
# ── 3. Semantic mapping ───────────────────────────────────────────────
mapper = SemanticMapper(cfg)
result = mapper.map(textbox_answers, pdf_field_names)
print(result.report())
Comment on lines +35 to +38
ts = datetime.now().strftime("%Y%m%d_%H%M%S")

output_pdf = pdf_form[:-4] + "_" + ts + "_filled.pdf"
validation_report_path = pdf_form[:-4] + "_" + ts + "_validation_report.json"
details: dict[str, Any] = {}
required_fields: list[str] = template_config.get("required_fields", []) if template_config else []

missing_required = [k for k in required_fields if not extracted.get(k)]
Comment on lines +130 to +134
if positional_values:
reasons.append("POSITIONAL_FALLBACK_USED")

if unmatched_pdf_fields:
reasons.append("PDF_FIELDS_UNMATCHED")
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

2 participants