Playbook Agent: hard rule engine (4/8)

Draft
RA
5mo ago
+1481-0

Summary

Deterministic rules evaluated before the LLM. When a hard rule fires, its outcome is locked — the LLM cannot override it.

Part 4 of 8 — depends on #574 (query catalog).

Why this matters

Critical cases must never be left to probabilistic reasoning. A known CSAM series hash match is always REPORT_AND_REMOVE — no model drift, no hallucination risk.

hardRuleEngine.ts

  • evaluateHardRules(): evaluate rules in priority order, return first match
  • Simple expression format: "catalog_id.field_name == 'VALUE'"
  • Operators: ==, !=, >=, <=, >, <
  • Matches against any row in the query result set
  • Returns undefined if no rules match (LLM verdict is used)

hardRuleEngine.test.ts — 8 tests

  • First matching rule wins (priority order)
  • Falls through to second rule when first doesn't match
  • Returns undefined when no rules match
  • Handles missing/failed query results gracefully
  • Matches across any row in the result set
  • Supports != operator

Test plan

  • npm test -- --testPathPattern=hardRuleEngine passes (8 tests)

Depends on #574 Query catalog. Merge #572, #573, #574 first.

Summary by CodeRabbit

  • New Features

    • Introduced Playbook Agent framework for configuring and executing deterministic guardrail rules and LLM-assisted decision logic.
    • Added hard rule engine for evaluating guardrail conditions before LLM processing.
    • Added query catalog system for managing and validating SQL templates.
    • Added playbook validation and loading from configuration files.
  • Tests

    • Added comprehensive test coverage for playbook parsing, hard rule evaluation, and query catalog resolution.

Part of #659