[FEAT]: Validation gates input extraction json pdf#279
Open
Aryama-srivastav wants to merge 4 commits intofireform-core:mainfrom
Open
[FEAT]: Validation gates input extraction json pdf#279Aryama-srivastav wants to merge 4 commits intofireform-core:mainfrom
Aryama-srivastav wants to merge 4 commits intofireform-core:mainfrom
Conversation
There was a problem hiding this comment.
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 intofiller.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>
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.
Description
Implemented three-stage validation checkpoints in the form-filling pipeline to improve measurable robustness before production.
What changed
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