Skip to content

Input Validation for Rules#103

Open
ColtonPayne wants to merge 10 commits intomainfrom
add-rule-parser-validation
Open

Input Validation for Rules#103
ColtonPayne wants to merge 10 commits intomainfrom
add-rule-parser-validation

Conversation

@ColtonPayne
Copy link
Collaborator

@ColtonPayne ColtonPayne commented Jan 30, 2026

Summary

Closes #104

Adds comprehensive input validation to the rule parser (rule_parser.py) so that malformed rules, invalid bounds, and bad parameters produce clear, actionable error messages instead of cryptic runtime failures.

Changes

  • Entry-point validation — rule text must be a non-empty string with exactly one <- separator; head and body must both be non-empty after splitting
  • Predicate & variable name validation — names must match [a-zA-Z_][a-zA-Z0-9_]*; digit-leading names and special characters are rejected with specific messages
  • Bound validation — intervals must contain exactly two finite numeric values in [0, 1] with lower <= upper; NaN, Inf, and out-of-range values are caught
  • Negation with explicit bounds~pred(X):[l,u] now correctly computes [1-u, 1-l] for both head and body clauses
  • :True / :False shorthand — body and head bounds accept boolean string literals as aliases for [1,1] and [0,0]
  • Double negation detection~~ in head or body raises immediately
  • forall() syntax validation — the inner expression must contain a predicate with variables
  • Threshold validation — empty dicts, negative keys, and length mismatches raise ValueError
  • Weight validation — must be numeric, finite, non-negative, and match clause count; plain lists are auto-converted to np.float64 arrays
  • Error type cleanup — generic Exception raises replaced with TypeError / ValueError
  • Refactored internals — extracted _split_body_into_clauses, _parse_head, _validate_predicate_name, and _validate_variable_name helpers
  • Makefile typo fix — corrected don_disable_jitdont_disable_jit in test suite target

Test coverage

Added 722-line test file (tests/unit/dont_disable_jit/test_rule_parser.py) with three test classes:

  • TestValidRuleParsing — node/edge rules, temporal deltas, annotation functions, bounds, negation, :True/:False, forall, head functions, thresholds, weights, and a complex combined-parameter case
  • TestInvalidRuleParsing — type errors, empty inputs, missing arrows, bad bounds, wrong-length thresholds/weights, NaN/Inf weights, malformed forall
  • TestEdgeCasesAndBoundary — boundary bounds, large delta_t, all six comparison operators, single-char predicates, negation inversion arithmetic, NaN/Inf bounds, digit-leading names, double negation

🤖 Generated with Claude Code

@ColtonPayne ColtonPayne changed the title Parser Rule Validation (WIP - DO NOT MERGE) Parser Rule Validation Feb 4, 2026
@ColtonPayne ColtonPayne added the Ready for Review Awaiting PR Review label Feb 4, 2026
@ColtonPayne ColtonPayne changed the title Parser Rule Validation Input Validation for Rules Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for Review Awaiting PR Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Input Validation for Rule Parser

2 participants