Skip to content

CLIPS+LLM Hybrid Integration

Demonstrates combining CLIPS expert system with LLM for deterministic business rules plus natural language understanding.

Combine deterministic CLIPS rules with LLM reasoning to build AI pipelines that are both fluent and auditable.

Community — runs on the OSS / Community SDK edition.

The CLIPS stage uses provider chat (JSON ClipsInput in the user message, ClipsOutput in content). See go/clips_wire.go and Rust crate examples/shared/clips-wire-rust. For Session API usage, use the CLIPS session bindings in your language SDK instead.

Schema: conformance/clips-json-contract.json. Documentation: nxusKit SDK sdk-packaging/docs/rule-authoring.mdClipsInput JSON Reference (#clipsinput-json-reference; bundle: docs/rule-authoring.md).

Difficulty: Intermediate 🟦 · LLM · CLIPS

  • Summary: Hybrid CLIPS rules + LLM reasoning
  • Scenario: Combine deterministic CLIPS rules with LLM-based reasoning
  • tech_tags in manifest: CLIPS, LLM — example id clips-llm-hybrid in conformance/examples_manifest.json.
  • SDK: Use an installed SDK tree (NXUSKIT_SDK_DIR, NXUSKIT_LIB_PATH as needed); test-examples.sh resolves Go/Rust/Python deps from that tree only — see README.md, scripts/setup-sdk.sh, and scripts/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).
  • Models: Set cloud provider API keys and/or run Ollama locally when you execute the Run steps (interactive flags like --help / --verbose are documented below).
  • CLIPS: Use an SDK build with CLIPS support (native libnxuskit); rule files and JSON contracts are referenced from this repo’s conformance/ docs.
FeatureDescriptionRustGo
ClipsProviderRule-based expert system as LLMProviderClipsProvider::builder()NewClipsProvider()
JSON Fact AssertionConvert structured data to CLIPS factsChatRequest with JSONChatRequest with JSON
Conclusion ExtractionParse CLIPS output for derived factsClipsOutput::conclusionsClipsOutput.Conclusions
Provider AbstractionSame interface for LLM and CLIPSLLMProvider traitLLMProvider interface
ResponseFormatStructured JSON output from LLMResponseFormat::JsonJSONMode: true
Hybrid PipelineLLM → CLIPS → LLM workflowanalyze_ticket()AnalyzeTicket()

Explainable AI decisions, regulated industry automation.

CLIPS, LLM

This example shows the “hybrid AI” pattern: using LLM for natural language understanding and CLIPS for deterministic business decisions. Both Rust and Go implementations use the real ClipsProvider to execute CLIPS rules.

ApproachStrengthsWeaknesses
LLM onlyNatural language understanding, flexibilityInconsistent policy application, no audit trail
CLIPS onlyDeterministic, auditable, policy-compliantCan’t understand unstructured text
HybridBoth! Understanding AND complianceMore complex architecture
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Step 1 │ │ Step 2 │ │ Step 3 │
│ LLM │ ──► │ CLIPS │ ──► │ LLM │
│ (classify) │ │ (routing) │ │ (response) │
└─────────────┘ └─────────────┘ └─────────────┘
Extract Apply rules Generate
category, deterministic empathetic
priority, team routing, customer
sentiment SLA, escalation response
  1. LLM Classification: Extract category, priority, sentiment, entities from ticket text
  2. CLIPS Routing: Apply deterministic rules for team assignment, SLA, escalation
  3. LLM Response: Generate appropriate customer response

The CLIPS rules in ticket-routing.clp apply:

CategoryPriorityTeamSLAEscalation
SecurityAnySecurity4hLevel 2
InfrastructureCriticalSRE2hLevel 1
InfrastructureHighSRE4hLevel 1
ApplicationCriticalDevelopment4hLevel 1
ApplicationHighDevelopment8hNone
GeneralAnyGeneral Support24hNone
use clips_llm_hybrid::analyze_ticket;
use std::path::Path;
// nxusKit: Hybrid analysis using LLM + ClipsProvider
let rules_path = Path::new("ticket-routing.clp");
let result = analyze_ticket(&provider, "llama3", ticket_text, rules_path).await?;
// Deterministic routing from CLIPS (auditable, explainable)
println!("Team: {}", result.team);
println!("SLA: {} hours", result.sla_hours);
// LLM-derived insights (natural language understanding)
println!("Sentiment: {}", result.sentiment);
println!("Response: {}", result.suggested_response);
// nxusKit: Hybrid analysis using LLM + ClipsProvider
rulesPath := "ticket-routing.clp"
result, err := AnalyzeTicket(ctx, provider, "llama3", ticketText, rulesPath)
// Deterministic routing from CLIPS (auditable, explainable)
fmt.Println("Team:", result.Team)
fmt.Println("SLA:", result.SLAHours, "hours")
// LLM-derived insights (natural language understanding)
fmt.Println("Sentiment:", result.Sentiment)

Attach an installed SDK (NXUSKIT_SDK_DIR). See the repository README.md and scripts/test-examples.sh.

Terminal window
# From `/examples/integrations/clips-llm-hybrid`:
cd rust && cargo build
cd go && make build
Terminal window
cd rust
cargo run
Terminal window
cd go
go run .

All examples support debugging flags:

Terminal window
# Verbose mode - show raw HTTP request/response data
cargo run -- --verbose # Rust
go run . --verbose # Go
# Step mode - pause at each step with explanations
cargo run -- --step # Rust
go run . --step # Go
# Combined mode
cargo run -- --verbose --step

Or use environment variables:

Terminal window
export NXUSKIT_VERBOSE=1
export NXUSKIT_STEP=1

See ticket-routing.clp for the actual CLIPS rules used in the Rust implementation.

Terminal window
# Rust
cd rust && cargo test
# Go
cd go && go test -v
  1. Rule versioning: Track changes to CLIPS rules with version control
  2. Audit logging: Log all routing decisions with rule traces
  3. Fallback handling: Define default routing for edge cases
  4. Rule testing: Unit test CLIPS rules independently of LLM
  5. Performance: Cache common routing patterns