Introducing a Python-Based Reasoning Engine for Deterministic AI

As the demand for deterministic systems grows reviving foundational ideas for the age of large language models (LLMs) is here.

The Challenge

One of the critical issues with modern AI systems is establishing constraints around how they validate and reason about incoming data. As we increasingly rely on stochastic LLMs to process unstructured data, enforcing rules and guardrails becomes vital for ensuring reliability and consistency.

The Solution

Thus a company has developed a Python-based reasoning and validation framework inspired by Pydantic, designed to empower developers and non-technical domain experts to create sophisticated rule engines. The system is:

  • Extensible: Developers can easily customize it to fit specific use cases.
  • Automated: A fine-tuned model generates rules from natural language instructions, streamlining the process.
  • Versatile: Applicable across industries with similar logic frameworks, such as logistics or compliance.

By transforming Standard Operating Procedures (SOPs) and business guardrails into enforceable code, this symbolic reasoning framework addresses the need for structured, interpretable, and reliable AI systems.

Key Features

  • Compatibility with Graph Data: Works with JSON-based graph data structures but is adaptable to relational and NoSQL databases.
  • Python-Based: Avoids the complexity of semantic tools like SHACL and RDF, providing a developer-friendly experience within familiar Python ecosystems.
  • Integrated State Machines: Supports reasoning and decision-making processes with state tracking.

System Architecture

The framework includes five core components:

  1. Data Structure: Represents the objects or elements within the system (e.g., chess pieces in a game analogy).
  2. Rules: Define the constraints or logic for the system (e.g., rules of chess).
  3. Reasoning Framework: Simulates decision-making processes (e.g., the chess player).
  4. Agent: Executes actions based on decisions (e.g., moving the chess pieces).
  5. State Machine: Tracks the system’s current state and transitions (e.g., the chessboard layout).

Types of Engines

  • Validation Engines: Focus on rule compliance, validating inputs without maintaining state.
  • Reasoning Engines: Navigate complex problem spaces, making decisions based on defined rules and a state machine.

Case Studies

1. Validation Engine: Mining Company Compliance

A mining company needed to validate employee qualifications against region-specific requirements. The system was configured to check rules such as minimum age and required certifications for specific roles.

Input Example:
Employee data and validation rules were modeled as JSON:

jsonCopy code{
  "employees": [
    { "name": "Sarah", "age": 25, "documents": [{ "type": "safe_handling_at_work" }] },
    { "name": "John", "age": 17, "documents": [{ "type": "heavy_lifting" }] }
  ],
  "rules": [
    { "type": "min_age", "parameters": { "min_age": 18 } }
  ]
}

Output:
Violations, such as “Minimum age must be 18,” were flagged immediately, enabling quick remediation.


2. Reasoning Engine: Solving the River Crossing Puzzle

To showcase its capabilities, we modeled the classic river crossing puzzle, where a farmer must transport a wolf, a goat, and a cabbage across a river without leaving incompatible items together.

Steps Taken:

  1. Translated the puzzle into data structures and rules.
  2. Enabled natural language input to add and modify rules.
  3. Used the engine to solve the puzzle while tracking states and ensuring rule compliance.

Enhanced Scenario:
Adding a new rule—“Wolf cannot be left with a chicken”—created an unsolvable scenario. By introducing a compensatory rule, “Farmer can carry two items at once,” the system adapted and solved the puzzle with fewer moves.


Developer Insights

The system supports rapid iteration and debugging. For example, adding rules is as simple as defining Python classes:

pythonCopy codeclass GoatCabbageRule(Rule):
    def evaluate(self, state):  
        return not (state.goat == state.cabbage and state.farmer != state.goat)  

    def get_description(self):  
        return "Goat cannot be left alone with cabbage"

Real-World Impact

This framework accelerates development by enabling non-technical stakeholders to contribute to rule creation through natural language, with developers approving and implementing these rules. This process reduces development time by up to 5x and adapts seamlessly to varied use cases, from logistics to compliance.

🔔🔔 Follow us on LinkedIn 🔔🔔

Related Posts
Who is Salesforce?
Salesforce

Who is Salesforce? Here is their story in their own words. From our inception, we've proudly embraced the identity of Read more

Salesforce Marketing Cloud Transactional Emails
Salesforce Marketing Cloud

Salesforce Marketing Cloud Transactional Emails are immediate, automated, non-promotional messages crucial to business operations and customer satisfaction, such as order Read more

Salesforce Unites Einstein Analytics with Financial CRM
Financial Services Sector

Salesforce has unveiled a comprehensive analytics solution tailored for wealth managers, home office professionals, and retail bankers, merging its Financial Read more

AI-Driven Propensity Scores
AI-driven propensity scores

AI plays a crucial role in propensity score estimation as it can discern underlying patterns between treatments and confounding variables Read more