Validating packets

Enterprise

Validation rules for cross-class fields ensure data quality and consistency across documents within a packet. While class-level validation rules verify individual field results, cross-class validation rules verify relationships between fields, selection logic, and data consistency.

Understanding cross-class validation rules

Cross-class validation rules focus on relationships and consistency across documents.

Cross-class validation rules flag results where input fields failed validation or were inconsistent across the packet.

Each cross-class validation rule must be associated with a specific cross-class field. This association determines where validation failures appear in human review and run results, making it clear which field needs attention. For referenced field rules, the associated field is the one being validated. For custom validation functions, the associated field is where failures display, though your custom function logic can validate any aspect of the packet.

Creating cross-class validation rules

Create cross-class validation rules to flag questionable results for human review.

  1. From the Cross-class tab, select Validations.

  2. Click Add cross-class rule.

  3. Select a validation rule type.

  4. Select the cross-class field that the validation rule applies to, and click Save.

    Cross-class validation results aren’t automatically recalculated when you modify input field validations. To update cross-class validation results, refresh the page.

Cross-class validation rule types

Choose the validation rule type that matches how you want to validate data across classes.

  • Validate selected field β€” Checks that the field selected by ranking logic is valid. Applies only to ranked, not derived, fields. Use this rule type when your selection criteria is based on confidence score rather than validation status, ensuring that the final selected value meets quality standards even if it was chosen based on confidence rather than validity.

  • Validate all input fields β€” Checks that every input field used to calculate the cross-class field is valid. Use this rule type when you want to verify packet integrity and ensure all documents in the packet contain valid data.

  • Require matching fields β€” Checks that all input field results match each other exactly. Use this rule type to detect inconsistencies across documents that might indicate data entry errors, fraud, or incorrectly grouped documents.

  • Validation function β€” Uses a custom Python function to validate cross-class field results. Use this rule type for complex validation logic that can’t be achieved with quick validation rules. For more details, see Cross-class validation function.

Cross-class validation function

For advanced validation requirements involving complex business logic, external data verification, or mission-critical results, create a custom cross-class validation function in Python.

When creating a validation function, you first select which cross-class field the rule applies to. This determines where validation failures are displayed in human review and run results. Your custom function logic can validate any aspect of the packet, not just the selected field. To use other fields in your custom function, click + Add argument and select the field from the dropdown. A 'class_fields' argument is added to your custom function, which you can use to access the field.

For example, you might use a validation function to verify that values across multiple documents fall within acceptable ranges:

1def validate_income_consistency(applicant_income, context, class_fields):
2 """
3 Validates that income values across documents are reasonably consistent.
4 Checks that the applicant income from the cross-class field falls within
5 an acceptable variance when compared to supporting documents.
6 """
7 # Skip validation if input is empty
8 if not applicant_income:
9 return "Income value is missing"
10
11 try:
12 # Convert income to float for comparison
13 income_value = float(applicant_income.replace(',', '').replace('$', ''))
14
15 # Collect all income values from input documents
16 income_values = []
17 for class_name, fields in class_fields.items():
18 if 'income' in fields:
19 field_value = fields['income'].get('value')
20 if field_value:
21 clean_value = float(field_value.replace(',', '').replace('$', ''))
22 income_values.append(clean_value)
23
24 # Check if values are within 10% variance
25 if income_values:
26 max_income = max(income_values)
27 min_income = min(income_values)
28 variance = (max_income - min_income) / max_income
29
30 if variance > 0.10:
31 return f"Income values vary by more than 10% across documents"
32
33 # Validation passed
34 return None
35
36 except (ValueError, AttributeError):
37 return f"Invalid income format: {applicant_income}"

Cross-class validation functions accept these parameters:

ParameterRequired?Description
<field-name>RequiredValue of the cross-class field that the function is associated with.
contextRequiredStores metadata about the packet.
context['class_fields']OptionalAccess to input field values organized by class name and field name. Use context['class_fields']['Class Name']['Field Name']['value'] to retrieve values.
context['document_text']OptionalRetrieves the entire text of all documents in the packet.
context['file_path']OptionalRetrieves the path to the uploaded packet.
keysOptionalAccess custom variables and organization secrets. Use keys['custom']['<key-name>'] for custom keys and keys['secret']['<key-name>'] for secret keys.
<additional-field-name>OptionalClick Add argument to select additional cross-class fields to use in the function.

Validation functions must return None if the validation rule passes, and an error string if the validation rule fails.

For additional guidance about custom functions, see Writing custom functions.

Best practices for packet validation

Choose validation rules that align with your quality requirements and use case.

Validation rule typeBest forNotes
Validate selected fieldData quality assuranceEnsures the final output meets quality standards. Particularly useful when selection logic prioritizes confidence scores over validation status, catching situations where high-confidence results are actually invalid.
Validate all input fieldsPacket integrity verificationVerifies that the entire packet contains high-quality data, not just the field that was selected. Helps identify incomplete documents, poor quality scans, or missing information across the packet.
Require matching fieldsConsistency and fraud detectionDetects inconsistencies that might signal fraud, data entry errors, or incorrect document grouping. Critical for compliance-focused use cases where document consistency is a key verification requirement.
Validation functionComplex business logicEnables external data verification, multi-step business rules, or calculations that can’t be achieved with quick validation rules. Allows domain-specific logic and integration with external systems.

Consider the cost of sending invalid results downstream versus the cost of human review when configuring validation rules. Stricter validation rules like Validate all input fields or Require matching fields catch more potential issues but send more packets to review. Less strict rules like Validate selected field minimize review burden but might miss edge cases. Choose validation strategies that align with your risk tolerance and review capacity.