A Lightweight Rule Engine
Policy as data
Store rules in JSON or YAML so reviewers can see and version policy without changing the enforcement algorithm. A rule engine loads the file, checks its schema, applies each relevant rule, and returns a decision plus stable reason codes such as too_long, blocked_pattern, or bad_status.
This course uses a NeMo-Guardrails-style engine, not the NeMo Guardrails library. NeMo Guardrails is a capable conversational safety framework, but its broad integration stack is disproportionate for isolated exercises on a shared two-CPU host. The small engine teaches the same core pattern - declarative rails around model input and output - with Python's standard library and transparent behavior.
Note: 'Style' is important: this lab does not claim API or configuration compatibility with NeMo Guardrails. Production teams should evaluate the real framework, policy needs, supported models, dependency footprint, and operational budget.
Validate the configuration at startup. Unknown rule names, invalid regexes, missing objects, or impossible limits should stop readiness rather than silently disable protection. Keep safe defaults in code and use least-permissive merge behavior.
Tip: Stable reason codes are safer for metrics and tests than parsing a human sentence. User-facing explanations can be mapped from those codes.