Validation rules not only support model accuracy but also help identify documents that fail to meet business requirements.

Creating validation rules
Affinda allows you to create powerful, flexible validation rules using natural language prompts. Simply describe the business logic you want to apply, and Affinda will automatically generate th e code needed to enforce it, no manual coding required.Steps to Create a Validation Rule
1
Go to Field Configuration
In the document validation interface, click “Configure Fields” in the top right corner
2
Add a New Validation Rule
Either select the pencil icon on the field you want to apply logic to or click the Validation tab, then select “Add Validation Rule”.
3
Describe the Rule in Natural Language
To reference specific fields, type @ and choose from the list. Validation rules can be created with just one or multiple fields.Clearly describe the condition or constraint. Add detail for more complex logic.Rules are created with the annotated field in the opened document as an example.As a best practice, create validation rules on documents that accurately reflect how the fields usually appear.
4
Click "Generate"
Affinda will produce the corresponding rule logic based on your description.
5
Review and Refine
After generation, you can review the underlying code, tweak the prompt, and re-generate the rule as needed to refine the behavior.

Pass and fail messages
When you generate a rule, Affinda also creates default messages to display when the rule passes or fails. These messages are shown to users in the validation UI and help explain the outcome of the rule. You can customize these messages by including guidance in your natural language prompt—for example, specify what the pass/fail messages should say to make them clearer or more specific for end users.Example: “Ensure the invoice date is before the due date. If not, show: ‘Due date cannot be earlier than invoice date.”
Missing data handling
In the Advanced Settings, users can define how a validation rule should behave if one or more of the referenced fields are not predicted. This is especially useful for rules involving multiple fields, where some fields may be optional or not consistently extracted. Available Options:- Skip
The rule is skipped entirely—no pass or fail outcome is recorded. - Fail
The rule automatically fails if any required field is missing. - Pass
The rule is marked as passed, regardless of missing fields. - Ignore
The rule runs by treating missing fields as neutral, attempting to return a valid result based on available data.- For example, useful in cases like subtotal + freight + tax = total, where freight is occasionally absent.