Ruler - Natural Language to CLIPS Rule Generation
A command-line tool for generating CLIPS rules from natural language descriptions using LLM, with validation and automatic retry logic.
Turn plain English into validated CLIPS rules — describe your business logic, get production-ready expert system code with automatic error correction.
Scenarios: generate · validate · save · load · examples
Edition
Section titled “Edition”Pro — requires a Pro (or trial) entitlement.
What this demonstrates
Section titled “What this demonstrates”Difficulty: Advanced ♦🏁 · LLM · CLIPS
- Summary: CLIPS rule authoring and execution app
- Scenario: Author, load, and execute CLIPS rules interactively
tech_tagsin manifest:CLIPS— example idrulerinconformance/examples_manifest.json.
Prerequisites
Section titled “Prerequisites”- SDK: Use an installed SDK tree (
NXUSKIT_SDK_DIR,NXUSKIT_LIB_PATHas needed);test-examples.shresolves Go/Rust/Python deps from that tree only — see README.md,scripts/setup-sdk.sh, andscripts/test-examples.sh. - Languages in this example: go, rust (paths under this directory; Python may live under a sibling
python/or shared reference per Language Implementations). - CLIPS: Use an SDK build with CLIPS support (native
libnxuskit); rule files and JSON contracts are referenced from this repo’sconformance/docs.
Real-World Application
Section titled “Real-World Application”Business rules workbench, rule management console.
Requirements
Section titled “Requirements”Edition: nxusKit Pro
This example requires the Pro edition of nxusKit. Purchase Pro or start a free 30-day trial (automatic on first Pro feature call).
Technologies
Section titled “Technologies”CLIPS
Language Implementations
Section titled “Language Implementations”| Language | Path | Status |
|---|---|---|
| Rust | rust/ | Available |
| Go | go/ | Available |
Attach an installed SDK (NXUSKIT_SDK_DIR). See the repository README.md and scripts/test-examples.sh.
# From `/examples/apps/ruler`:cd rust && cargo buildcd go && make buildFeatures
Section titled “Features”- Natural Language Input - Describe rules in plain English
- CLIPS Code Generation - Produces valid CLIPS deftemplates and defrules
- Automatic Validation - Validates generated code against CLIPS syntax
- Retry with Feedback - Automatically retries with error feedback on failures
- Progressive Examples - Built-in examples from basic to advanced complexity
- Multiple Output Formats - Save as .clp, .json, or binary
Installation
Section titled “Installation”cd examples/apps/ruler/rustcargo build --releasecd examples/apps/ruler/gomake buildcd examples/apps/ruler/rust
# Show helpcargo run -- --help
# Generate rules from natural languagecargo run -- generate "Create a rule that classifies adults if age >= 18"
# Generate with advanced complexitycargo run -- generate -c advanced "Medical triage expert system" -o triage.clp
# Run progressive examplescargo run -- examples -c basic
# Validate existing CLIPS codecargo run -- validate my-rules.clp
# Load and display rulescargo run -- load my-rules.clpcd examples/apps/ruler/go
# Show help./bin/ruler --help
# Generate rules./bin/ruler generate "Classify customers as gold if purchases > 5000"
# Generate with output file./bin/ruler generate -o customer.clp "Customer loyalty program rules"Commands
Section titled “Commands”generate
Section titled “generate”Generate CLIPS rules from a natural language description.
ruler generate <DESCRIPTION> [OPTIONS]
OPTIONS: -c, --complexity <LEVEL> Target complexity: basic, intermediate, advanced -m, --model <MODEL> LLM model to use (default: claude-haiku-4-5-20251001) -r, --retries <N> Max retry attempts (default: 5) -o, --output <FILE> Write output to file -j, --json Output in JSON format -v, --verbose Show detailed progressvalidate
Section titled “validate”Validate CLIPS code syntax and structure.
ruler validate <FILE> [OPTIONS]
OPTIONS: -v, --verbose Show detailed validation resultsexamples
Section titled “examples”Run built-in progressive complexity examples.
ruler examples [OPTIONS]
OPTIONS: -c, --complexity <LEVEL> Filter by complexity level -l, --list List examples without runningsave / load
Section titled “save / load”Save or load rule sets.
ruler save <FILE> # Save current rulesruler load <FILE> # Load rules from fileInteractive Modes
Section titled “Interactive Modes”All examples support debugging flags:
# Verbose mode - show raw HTTP request/response datacargo run -- --verbose # Rust./bin/ruler --verbose # Go
# Step mode - pause at each step with explanationscargo run -- --step # Rust./bin/ruler --step # Go
# Combined modecargo run -- --verbose --stepOr use environment variables:
export NXUSKIT_VERBOSE=1export NXUSKIT_STEP=1Complexity Levels
Section titled “Complexity Levels”- Simple single-rule definitions
- Basic deftemplates with few slots
- Straightforward conditions
Example: “Classify people as adults if age >= 18”
Intermediate
Section titled “Intermediate”- Multiple related rules
- Fact chaining and dependencies
- Moderate slot complexity
Example: “Customer loyalty program with bronze, silver, gold tiers”
Advanced
Section titled “Advanced”- Complex multi-rule systems
- Salience and conflict resolution
- Advanced pattern matching
Example: “Medical triage system with symptom analysis”
Example Output
Section titled “Example Output”Generated CLIPS Code
Section titled “Generated CLIPS Code”; Generated by Ruler from: "Classify adults if age >= 18"
(deftemplate person (slot name (type STRING)) (slot age (type INTEGER)))
(deftemplate classification (slot person-name (type STRING)) (slot category (type SYMBOL)))
(defrule classify-adult "Classify a person as an adult if age >= 18" (person (name ?name) (age ?age&:(>= ?age 18))) => (assert (classification (person-name ?name) (category adult))))Validation Result
Section titled “Validation Result”Validation: PASSEDTemplates: 2Rules: 1Warnings: 0Architecture
Section titled “Architecture”ruler/├── rust/│ ├── src/main.rs # CLI entry point│ └── Cargo.toml├── go/│ ├── cmd/main.go # CLI entry point│ ├── generator.go # Rule generation logic│ ├── validator.go # CLIPS validation│ └── go.mod└── shared/ └── examples/ # Built-in examplesRetry Logic
Section titled “Retry Logic”When generated code fails validation:
- Parse the validation error
- Include error context in retry prompt
- Adjust complexity hints if needed
- Retry up to N times (default: 5)
- Return best attempt if all retries fail
- CLIPS functionality uses ClipsProvider for validation
- LLM approach requires API key (ANTHROPIC_API_KEY or OPENAI_API_KEY)
- Generated code quality depends on description clarity
Testing
Section titled “Testing”# Rustcd examples/apps/ruler/rustcargo test
# Gocd examples/apps/ruler/gogo test -v ./...License
Section titled “License”Part of the nxusKit project.