Skip to content

[FEAT]: Add template schema registry with compatibility validation#289

Open
Aryama-srivastav wants to merge 3 commits intofireform-core:mainfrom
Aryama-srivastav:feature/template-schema-registry
Open

[FEAT]: Add template schema registry with compatibility validation#289
Aryama-srivastav wants to merge 3 commits intofireform-core:mainfrom
Aryama-srivastav:feature/template-schema-registry

Conversation

@Aryama-srivastav
Copy link

Description

Multiple PDF templates need predictable behavior and reproducibility across different form families:

  • Schema Registration: Eliminates guesswork about template structure
  • Pre-fill Validation: Catches incompatibilities before filling (fail fast)
  • Clear Reporting: Missing/extra/type-mismatched fields are documented
  • Multi-template Support: Template families enable consistent handling of related forms

What Changed

Added comprehensive template schema registry system with pre-fill compatibility checking:

template_schema.py

  • FieldSchema: Metadata for individual form fields (name, type, required, aliases, dependencies, max_length)
  • TemplateSchema: Complete template definition with fields, version, family, and metadata
  • TemplateRegistry: Multi-template management organized by family
  • CompatibilityReport: Detailed validation results with clear issue categorization
  • FieldType enum: Email, phone, date, number, checkbox, dropdown, text, unknown

compatibility_checker.py

  • CompatibilityChecker : Core validation engine for pre-fill checks
  • Multi-level compatibility validation: field mapping → type checking → dependency validation
  • Type-specific validators for email (@ check), phone (7+ digits), date (multiple formats), numbers, etc.
  • Family-wide compatibility checking across multiple templates
  • Template discovery by compatibility score for automatic template selection

filler.py — Enhanced with template support

  • New init(template_registry) parameter for optional registry
  • New method: check_compatibility_before_fill(template_id, extracted_data)
  • Returns compatibility report dict with matched/missing/extra/unmapped fields

test_template_schema.py

  • 23 comprehensive tests covering all acceptance criteria
  • Template registration, family grouping, field name resolution
  • Compatibility checking (valid data, missing fields, extra fields, aliases, type validation)
  • Date format validation (MM/DD/YYYY, YYYY-MM-DD, Month DD, YYYY)
  • Registry operations (update, delete, query)

Test Validation
✅ 23/23 tests pass — All acceptance criteria met

- Implement TemplateSchema and TemplateRegistry for managing PDF templates
- Support template metadata: required fields, aliases, type constraints, versioning
- Add CompatibilityChecker for pre-fill validation with detailed reporting
- Support template families for multi-template organization
- Comprehensive type validation (email, phone, date, number, checkbox, dropdown)
- Missing/extra fields detection and dependency tracking
- Integration with Filler.check_compatibility_before_fill()
- 23 comprehensive tests for all acceptance criteria
Copilot AI review requested due to automatic review settings March 18, 2026 17:42
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 template schema registry + compatibility validation layer to support predictable, reproducible PDF pre-fill behavior across multiple template “families”, and wires optional compatibility checks into the existing PDF filler.

Changes:

  • Introduces TemplateSchema / FieldSchema / TemplateRegistry and CompatibilityReport for template metadata and validation reporting.
  • Adds CompatibilityChecker to validate extracted data (mapping, required fields, type checks, dependencies) and to discover compatible templates.
  • Extends Filler with optional registry support and a check_compatibility_before_fill() helper; adds a comprehensive pytest suite.

Reviewed changes

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

Show a summary per file
File Description
src/template_schema.py New schema/registry/report datamodels for template metadata and compatibility reporting.
src/compatibility_checker.py New validation engine for template compatibility checks and template discovery.
src/filler.py Adds optional template-registry integration and a pre-fill compatibility check API.
src/test/test_template_schema.py Adds end-to-end unit tests for registry behaviors and compatibility validation.
src/inputs/input.txt Updates sample input content used for local/manual runs.

💡 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 +63 to +73
report.matched_fields.add(canonical_name)

# Type validation
type_issue = self._validate_field_type(
canonical_name,
extracted_value,
field_schema,
)
if type_issue:
report.type_mismatches[canonical_name] = type_issue
report.compatible = False
Comment on lines +46 to +47
# Track which fields we've seen
extracted_field_names = set(extracted_data.keys())
if canonical_name is None:
# Field not found in template
report.extra_fields.add(extracted_name)
report.unmapped_fields.add(extracted_name)
Comment on lines +103 to +113
"""
# Exact match
if extracted_name in self.fields:
return extracted_name

# Check aliases
for canonical_name, schema in self.fields.items():
if extracted_name in schema.aliases:
return canonical_name

return None
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