Rule Based Checks, Regular Expressions and Their Blind Spots

Rule Based Checks: The Foundation of Output Filtering

Rule based checks form the backbone of many guardrail implementations. These systems operate on predefined conditions that trigger when specific patterns or criteria are met. The approach works well for clearly defined problems such as blocking explicit content or preventing certain data formats.

In practice, these checks often take the form of simple if-then statements that evaluate input against known bad patterns.

Consider a customer service chatbot that must never share personal data. A rule-based check might look for patterns such as “customer ID”, “account number”, or “social security number” and immediately flag any message containing these terms. The system evaluates each input against these rules and makes a binary decision.

This approach works reliably when the rules are well-defined and the problem space is limited.

The strength of rule-based systems lies in their predictability. When a rule triggers, you know exactly why it triggered. This makes debugging straightforward and allows for quick adjustments when new threats emerge.

Many organisations implement these checks as the first line of defence against obvious violations. The approach requires minimal computational resources and provides immediate feedback.

Rule Based Checks, Regular Expressions and Their Blind Spots Concept Diagram
Figure: Conceptual architecture and workflow for Rule Based Checks, Regular Expressions and Their Blind Spots

Regular Expressions: Pattern Matching Power

Regular expressions offer a sophisticated way to define complex patterns within text. These expressions allow engineers to specify exactly what constitutes acceptable or unacceptable content through mathematical notation. In practice, regular expressions handle tasks such as email validation, phone number formatting, or identifying sensitive data patterns.

A practical example involves filtering financial data from customer communications. The system might use a regular expression pattern like d{4}-d{4}-d{4}-d{4} to identify potential credit card numbers. This pattern matches four groups of four digits separated by hyphens.

The expression makes it easier to identify these numbers without writing complex string parsing logic.

The flexibility of regular expressions enables engineers to create highly specific checks. For instance, a healthcare application might need to identify medical record numbers that follow a specific format such as Hd{3}-d{2}-d{4}. The expression allows for precise matching while avoiding false positives from similar but unrelated data.

Regular expressions also support case-insensitive matching, character classes, and quantifiers that make pattern definitions more flexible. These features allow engineers to create checks that work across different input variations while maintaining accuracy.

Video: Rule Based Checks, Regular Expressions and Their Blind Spots

Blind Spots and Common Failures

Despite their utility, rule-based systems and regular expressions have significant limitations that practitioners must understand. The primary blind spot involves context awareness. These systems cannot understand meaning or intent behind text.

A message containing “The bank account number is 1234-5678-9012-3456” might trigger a rule, but the same numbers appearing in a fictional story or example code would not.

The second major limitation involves evasion techniques. Sophisticated users can often bypass simple pattern matching through character substitution, encoding, or spacing variations. The string “1234-5678-9012-3456” might become “1234 5678 9012 3456” or “1234_5678_9012_3456” through simple transformation.

These variations can easily bypass basic regular expressions without proper consideration.

The third blind spot involves false positives. Well-intentioned rules can block legitimate content. A customer support system might block any message containing “password” because it matches a rule against sensitive data.

However, customers legitimately discuss passwords in support conversations. The system must balance protection against usability.

  • Character substitution bypasses through Unicode or special characters
  • Context-dependent meanings that regular expressions cannot interpret
  • False positives that block legitimate business communications
  • Overly broad patterns that catch unintended matches
  • Performance issues with complex regular expressions

The most effective guardrail implementations combine multiple approaches. Regular expressions work best when combined with machine learning models that understand context. Rule-based systems benefit from human review processes that catch edge cases.

Practitioners should always test their systems against diverse examples including edge cases, intentional evasion attempts, and legitimate variations of acceptable content.

Executive Advisory • Tesseract Consulting

Enterprise AI Strategy & Implementation Discovery Call

Scope practical AI workflows, human-in-the-loop governance, and measurable delivery milestones with Tesseract Consulting.