Rule Validation Agent
The Rule Validation agent validates documents or data against a defined set of rules. Each rule is evaluated independently, and the agent returns a pass/fail result for each rule along with an overall verdict.
Use Cases
- You need to check whether a document or dataset complies with a set of business rules.
- A compliance workflow requires systematic rule-by-rule evaluation.
- You want structured pass/fail output for auditing purposes.
Inputs
| Input | Type | Description |
|---|---|---|
document | Document | The document to validate against the rules. |
text | Text | (Alternative) Plain text to validate. |
data | JSON | (Alternative) Structured data to validate. |
Outputs
| Output | Type | Description |
|---|---|---|
overall_result | Boolean | true if all rules pass, false if any rule fails. |
rule_results | JSON | Per-rule results with rule name, pass/fail, and explanation. |
Configurations
| Parameter | Description | Default |
|---|---|---|
rules | List of rules to evaluate. Each rule has a name, description, and evaluation criteria. | Required |
fail_on_any | Whether to fail the overall result if any single rule fails. | true |
Deterministic Validation
The Rule Validation agent supports deterministic validation -- conditions that evaluate extracted data against rules without using an LLM. This is useful for exact checks like "does the PO amount match the invoice amount?" or "is the date within range?" You can define deterministic validations in two modes:
Condition Mode
A visual rule builder where you define conditions using extracted variables:
- LHS (Data field) -- reference extracted fields using double curly braces:
{{field_name}}. Chain methods on fields:{{field_name}}.method1(arg1).method2(arg2). - Operator -- compatible operators are shown based on the field type.
- RHS (Value) -- a fixed value, another variable, or a static function like
$now().
Examples:
{{PO Amount}} == {{Invoice Amount}}
{{Invoice Date}}.plus(30, "days") > $now()
{{Vendor Name}}.lower() == "acme corp"
{{PO Quantity}} >= {{Invoice Quantity}}
Currently, you can chain conditions with either ANDs or ORs, but not both in the same rule.
Supported operators by type:
| Type | Operators |
|---|---|
| Boolean | ==, != |
| Number | ==, !=, >, >=, <, <=, in, not in |
| String | ==, !=, substring, not substring, contains substring, does not contain substring, in, not in, substring in any of, substring not in any of |
| Datetime | >, >=, <, <=, in, not in |
Available functions:
| Function | Returns | Description |
|---|---|---|
$now() | Datetime | Current date and time |
.day() | Number | Day of the month (1-31) |
.month() | Number | Month of the year (1-12) |
.year() | Number | The year |
.hour() | Number | Hour of the day (0-23) |
.plus(n, interval) | Datetime | Adds a duration (seconds, minutes, hours, days, weeks, months, years) |
.minus(n, interval) | Datetime | Subtracts a duration |
.plus(n) (number) | Number | Adds n to the number |
.minus(n) (number) | Number | Subtracts n from the number |
.lower() | String | Converts to lowercase |
Code Mode
For more complex validation logic, switch to the Code tab for a JavaScript editor:
- Extracted fields are available as
inputs.field_name. - For boolean rules: return
"true"or"false"as a string. - For numerical rules: return a number.
- Use
log.info(),log.warning(), orlog.error()for Show Work visibility.
// Boolean validation with tolerance
function main(inputs) {
var poAmount = inputs.PO_Amount;
var invoiceAmount = inputs.Invoice_Amount;
if (poAmount === undefined || invoiceAmount === undefined) {
log.warning("Missing amount fields");
return "false";
}
var tolerance = 0.01;
var passed = Math.abs(poAmount - invoiceAmount) <= tolerance;
log.info(passed ? "Amounts match" : "Mismatch: PO=" + poAmount + ", Invoice=" + invoiceAmount);
return passed ? "true" : "false";
}
// Numerical scoring
function main(inputs) {
var score = 0;
if (inputs.PO_Amount === inputs.Invoice_Amount) score += 40;
if (inputs.PO_Quantity === inputs.Invoice_Quantity) score += 30;
if (inputs.PO_Unit_Price === inputs.Invoice_Unit_Price) score += 30;
log.info("Validation score: " + score);
return score;
}
How to Use This Agent
Validate an insurance claim document against policy rules:
document_trigger -> rule_validation -> [pass] -> intelligent_actions("Approve claim")
-> [fail] -> human_collaboration -> workflow_output
Related Agents
- Response Validator -- for validating AI-generated responses specifically.
- Extract Entities -- for extracting data from documents before rule validation.
- Custom Code Agent -- for standalone JavaScript logic outside of rule validation context.