Level 2 / Project 13 - Validation Rule Engine¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| Concept | This project | — | Quiz | Flashcards | Diagram | Browser |
Estimated time: 45 minutes
Focus¶
- rule evaluation and reason codes
Why this project exists¶
This project gives you level-appropriate practice in a realistic operations context. Goal: run the baseline, alter behavior, break one assumption, recover safely, and explain the fix.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-2/13-validation-rule-engine
python project.py data/sample_input.txt
python project.py data/sample_input.txt --verbose
pytest -q
Expected terminal output¶
Validated 8 records: 4 valid, 4 invalid (50.0% pass rate)
Most common failures: R003: 1, R001: 1, ...
12 passed
Expected artifacts¶
- Validation report on stdout
- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add a new rule type
"one_of"that checks if a value is in an allowed list. - Add a
--rulesflag to load rules from a separate JSON file. - Add a
--strictmode that stops validation after the first failure per record.
Break it (required) — Core¶
- Pass a record with a field that is an unexpected type (e.g. age as a list).
- Use an invalid regex pattern in a rule — does it crash?
- Feed an empty records array — does the pass_rate calculation divide by zero?
Fix it (required) — Core¶
- Guard the regex check against
re.errorexceptions. - Handle division by zero in pass_rate for empty batches.
- Add type checking before range validation.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- Why are rules defined as data instead of hard-coded if/else chains?
- How does the dispatch pattern (
if rule_type == ...) work? - What is the advantage of returning result dicts instead of printing directly?
- Where would a validation rule engine be used in production systems?
Mastery check¶
You can move on when you can: - add a new rule type without modifying existing rule checks, - explain data-driven design vs code-driven design, - write regex patterns for common validations (email, phone, URL), - describe how this pattern scales to complex validation scenarios.
Related Concepts¶
| ← Prev | Home | Next → |
|---|---|---|