Skip to main content

Business Rules

Configure automated validation and transformation rules for your extracted data using natural language prompts.

Overview

Business Rules provide a powerful way to implement custom validation logic and data transformations that go beyond standard field validation. Using natural language prompts, you can describe complex business requirements that are automatically converted into executable validation rules.

How Business Rules Work

Prompt-Based Rule Generation

  1. Write a prompt describing your business requirement in natural language
  2. Use # and @ to reference specific entities and groups from your extraction template
  3. Generate rule - AI converts your prompt into executable MongoDB aggregation query
  4. Test and refine - Validate rule behavior in the validation window
  5. Enable/disable - Control which rules are active during processing

Smart Entity and Group References

The prompt editor supports intelligent mentions:

  • # mentions - Reference specific extraction fields (entities)
    • Type # to see available entities
    • Example: #patient_name or #invoice_total
  • @ mentions - Reference template groups
    • Type @ to see available groups
    • Example: @header_info or @line_items

Creating Business Rules

Access Business Rules

  1. Go to Project SettingsPipelineStep Settings
  2. Navigate to Business Rules (marked as Beta)
  3. Click Create Rule to open the rule editor

Writing Effective Prompts

Example prompts:

  • "Ensure the #total_amount equals the sum of all #line_item amounts"
  • "If #country is 'US', then #tax_rate should not exceed 15%"
  • "Set #delivery_date to #invoice_date plus 30 days if #rush_delivery is false"
  • "Validate that #patient_age is between 0 and 120"

Best practices:

  • Be specific about the validation logic you want
  • Reference exact field names using # mentions
  • Describe the expected behavior clearly
  • Include error conditions and expected outcomes

Rule Properties

Each business rule includes:

  • Name - Descriptive identifier for the rule
  • Prompt - Your natural language description
  • Description - Auto-generated explanation of what the rule does
  • Query - Generated MongoDB aggregation pipeline
  • Target Fields - Fields affected by this rule
  • Priority - Execution order (lower numbers execute first)
  • Enabled - Whether the rule is active

Rule Management

Priority and Ordering

Rules execute in priority order:

  • Lower priority numbers execute first
  • Rules can depend on outputs from previous rules
  • Careful ordering prevents conflicts and ensures correct logic flow

Enable/Disable Rules

  • Toggle individual rules on/off without deletion
  • Test scenarios by enabling/disabling specific rule combinations
  • Gradual rollout by enabling rules incrementally

Testing Rules

Validation Window Testing:

  1. Process a document with your rules enabled
  2. Open the Validation tab to see results
  3. Look for rule application icons showing which rules were applied
  4. Review any validation errors or warnings generated
  5. Adjust rule prompts based on test results

Rule Execution

During Document Processing

Business rules execute automatically during the validation phase:

  1. Field validation runs first (required fields, data types, etc.)
  2. Business rules execute in priority order
  3. Rule application tracking - Icons show which rules were applied
  4. Results integration - Rule outputs update the document's data structure

Rule Application Indicators

When viewing validation results:

  • Icons appear next to fields affected by business rules
  • Hover for details about which rule was applied
  • Validation status shows success/warning/error for each rule
  • Rule execution logs available for debugging

Advanced Features

Context-Aware Rules

Rules can access the complete document structure:

  • Cross-field validation - Compare values between different fields
  • Group-level logic - Apply rules across template groups
  • Conditional logic - Rules that only apply under certain conditions
  • Data transformation - Modify field values based on business logic

Generated Code

Each rule produces a MongoDB aggregation query that:

  • Validates data according to your prompt requirements
  • Transforms values when business logic dictates changes
  • Adds validation messages for errors and warnings
  • Tracks rule applications for audit and debugging

Best Practices

Rule Design

  1. Start simple - Create basic rules first, then add complexity
  2. One purpose per rule - Keep each rule focused on a single validation
  3. Clear naming - Use descriptive rule names that explain their purpose
  4. Test thoroughly - Validate rules with various document types and edge cases

Performance

  1. Optimize order - Place frequently-triggered rules with lower priority
  2. Avoid conflicts - Ensure rules don't contradict each other
  3. Monitor execution - Track rule performance and processing times
  4. Regular review - Periodically assess rule effectiveness and accuracy

Business rules provide flexible, maintainable validation logic that adapts to your specific business requirements while remaining easy to understand and modify through natural language prompts.