Skip to main content

Explainable AI toolkit with pluggable explainer backends and optional IA service integration

Project description

XAI Suite

A generic, domain-agnostic Python toolkit for Explainable AI (XAI). Provides SHAP and LIME explainability methods with optional server-side narrative generation, actionable insights, and EU AI Act compliance documentation.

Part of the CyberNEMO Project

Overview

XAI Suite uses a hybrid architecture:

  • xai_suite (client library): SHAP/LIME run locally with your model
  • xai_suite_service (server): IA Narrative Engine + Insights + EU AI Act compliance
CUSTOMER ENVIRONMENT                          SERVER (Protected IP)
┌────────────────────────────────┐            ┌─────────────────────────────────────┐
│  Your ML Model                 │            │  XAI Suite Service                  │
│            │                   │            │                                     │
│  ┌─────────────────────────┐   │            │  ┌─────────────────────────────┐    │
│  │  xai_suite (client)     │   │            │  │  Domain Registry            │    │
│  │  - SHAP/LIME (local)    │   │  HTTP      │  │  - generic                  │    │
│  │  - IAClient             │───┼──────────▶ │  │  - cybersecurity            │    │
│  └─────────────────────────┘   │            │  │  - (extensible)             │    │
│                                │            │  └─────────────────────────────┘    │
│  Response includes:            │            │                                     │
│  - narrative                   │◀───────────│  IA Engine + Compliance Module      │
│  - insights                    │            │                                     │
│  - compliance                  │            │                                     │
└────────────────────────────────┘            └─────────────────────────────────────┘

Key Features

  • Domain-Agnostic: Works with any ML application through pluggable domain contexts
  • SHAP & LIME: Local explainability runs with your model
  • IA is Optional: Works standalone without the server
  • Actionable Insights: Domain-specific recommendations from explanations
  • EU AI Act Compliance: Audit logging and article references
  • Server-side LLM: Protects prompts and IP

Pluggable Domains

  • generic - Default fallback for any ML application
  • cybersecurity - Network security, firewall analysis, anomaly detection
  • Extensible for fraud, healthcare, financial, etc.

Installation

From PyPI

pip install xai-ia

From Source

# Install the client library
pip install -e .

# Install with server dependencies
pip install -e ".[server]"

# Install with all dependencies (including LLM backends)
pip install -e ".[all]"

Quick Start

Basic Usage (Local Only)

from xai_suite import XAIOrchestrator

# Initialize with your model
orchestrator = XAIOrchestrator(model, X_train)
orchestrator.add_explainer("shap")
orchestrator.add_explainer("lime", {"mode": "classification"})

# Generate explanations
result = orchestrator.explain(instance)
print(result["shap"]["importance_scores"])
print(result["lime"]["importance_scores"])

With IA Service (Recommended)

from xai_suite import XAIOrchestrator

orchestrator = XAIOrchestrator(model, X_train)
orchestrator.add_explainer("shap")

# Enable IA with domain context
orchestrator.enable_ia(
    endpoint="https://xai.your-server.com",
    api_key="your-api-key",
    domain="cybersecurity",  # or "generic"
    model_type="anomaly_detection"
)

result = orchestrator.explain(instance)

# Access results
print(result["shap"]["importance_scores"])  # Local SHAP values
print(result["narrative"]["text"])          # Human-readable narrative
print(result["insights"])                   # Actionable recommendations
print(result["compliance"]["applicable_articles"])  # EU AI Act references

Running the Examples

# Classification example (Iris dataset)
python examples/run_classification_example.py

# Anomaly detection example (requires data/hubble2.csv)
python examples/run_anomaly_detection_example.py

Running the IA Service

# Start the server
uvicorn xai_suite_service.main:app --reload

# Or with Docker
docker-compose up -d

Configure via environment variables:

  • XAI_LLM_BACKEND: template, ollama, openai, anthropic
  • XAI_API_KEYS: Comma-separated API keys
  • XAI_COMPLIANCE_ENABLED: Enable EU AI Act logging

API Endpoints

Endpoint Method Description
/api/v1/health GET Health check with available domains
/api/v1/domains GET List available domain contexts
/api/v1/narrative POST Generate narrative (v1 legacy)
/api/v1/v2/explain POST Generate narrative + insights + compliance (v2)

V2 API Response Example

{
  "narrative": {
    "text": "The anomaly detection model flagged this traffic...",
    "method": "SHAP",
    "domain": "cybersecurity",
    "timestamp": "2026-02-04T10:30:00Z"
  },
  "insights": [
    {
      "type": "warning",
      "priority": "high",
      "title": "SYN Flood Pattern Suspected",
      "description": "High SYN count relative to ACK suggests...",
      "action": "Enable SYN cookies, implement rate limiting",
      "related_features": ["syn_count", "ack_count"]
    }
  ],
  "compliance": {
    "audit_id": "audit-2026-02-04-abc123",
    "timestamp": "2026-02-04T10:30:00Z",
    "applicable_articles": [
      {
        "article": "article_13",
        "title": "Transparency and provision of information",
        "relevance": "XAI explanations support transparency requirements"
      }
    ]
  }
}

Project Structure

xai-suite/
├── xai_suite/                    # Client library
│   ├── orchestrator.py           # Main entry point
│   ├── explainers/               # SHAP, LIME implementations
│   ├── utils/                    # Model wrapper, visualization
│   └── ia/                       # IA client (HTTP)
│
├── xai_suite_service/            # Server service
│   ├── main.py                   # FastAPI app
│   ├── api/                      # API routes (v1 + v2)
│   ├── ia_engine/
│   │   ├── domains/              # Pluggable domain contexts
│   │   ├── narrative.py          # Narrative generation
│   │   ├── insights.py           # Insight generation
│   │   └── llm_backends.py       # LLM integrations
│   └── compliance/               # EU AI Act logging
│
├── examples/                     # Example scripts
├── data/                         # Sample datasets
└── pyproject.toml

Extending the System

Adding New Domains

# xai_suite_service/ia_engine/domains/your_domain.py
from xai_suite_service.ia_engine.domains.base import DomainContext

class YourDomain(DomainContext):
    @property
    def domain_id(self) -> str:
        return "your_domain"

    @property
    def display_name(self) -> str:
        return "Your Domain"

    def get_feature_description(self, feature_name: str):
        # Return domain-specific feature descriptions
        ...

    def detect_patterns(self, feature_values: dict):
        # Detect domain-specific patterns
        ...

    def get_recommendations(self, feature_importances, patterns, prediction_value):
        # Generate domain-specific recommendations
        ...

    def get_system_prompt(self) -> str:
        # Return LLM system prompt for this domain
        ...

Adding New Explainers

  1. Inherit from BaseExplainer in xai_suite/explainers/
  2. Implement _initialize_explainer() and explain_local()
  3. Register in XAIOrchestrator.AVAILABLE_EXPLAINERS

Requirements

Client Library:

  • Python 3.10+
  • scikit-learn, shap, lime, numpy, pandas, matplotlib
  • httpx, pydantic (for IA integration)

Server Service:

  • FastAPI, uvicorn, pydantic-settings
  • Optional: ollama, openai, anthropic SDKs

License

This project is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

Copyright 2026 Maggioli SPA

Author

Costas Vrioni (costas.vrioni@maggioli.gr)

Developed as part of the CyberNEMO research initiative.

Related Work

  • SHAP (Lundberg & Lee, 2017)
  • LIME (Ribeiro et al., 2016)
  • EU AI Act - Regulation (EU) 2024/1689

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xai_ia-0.4.2.tar.gz (31.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xai_ia-0.4.2-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file xai_ia-0.4.2.tar.gz.

File metadata

  • Download URL: xai_ia-0.4.2.tar.gz
  • Upload date:
  • Size: 31.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for xai_ia-0.4.2.tar.gz
Algorithm Hash digest
SHA256 7071b46bd07b2045dba97c020db105334178f256bded70a7e046e28c83ec61b8
MD5 68f2b109c503dd03af45d67615f29fd1
BLAKE2b-256 f16c412281d4d6aca0e4f1c9ccdb159e30c22b3c724eec5a040d3f4f55550478

See more details on using hashes here.

File details

Details for the file xai_ia-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: xai_ia-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 26.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for xai_ia-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2a8c5a141b3fe25ffc628920e09f334bbbb013a1c70270ac991a84d1e5ff457a
MD5 1a9b764a9ba498611e77989749e9a531
BLAKE2b-256 60e614353aba183948d8e4aa9f5b67093c6dc8ec7dc4d8f02ab6161d5ec62d43

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page