Skip to content

Repository files navigation

EASA Compliance Parser

Python 3.10+ License: MIT

Parser and semantic search system for EASA (European Union Aviation Safety Agency) regulations. Optimized for integration with RAG (Retrieval Augmented Generation) systems.

✨ Features

  • βœ… Official EASA structure-based parser : Uses the EASA eRules XML Export XSD schema
  • βœ… 3,357+ topics extracted : Complete access to all regulations (IR, AMC, GM, CS)
  • βœ… Batch processing : Parse all XML files in a directory automatically
  • βœ… Universal parser : Automatically detects EASA document location (item2.xml, item9.xml, etc.)
  • βœ… Semantic search : Embeddings with sentence-transformers for similarity search
  • βœ… Complete metadata : Dates, regulatory sources, content types
  • βœ… Optimized performance : SDT indexing in O(n) for fast parsing (~5 seconds)
  • βœ… MCP Server : Integration with Model Context Protocol for LLMs
  • βœ… Chat Client : CLI interface to chat with LLMs connected to EASA regulations
  • βœ… CrewAI Compliance : Automated audit with AI agent team (Auditor + QA)

πŸ“¦ Installation

# Clone the repository
git clone https://github.com/dmoraine/easacompliance.git
cd easacompliance

# Install with pip
pip install -e .

# Or with uv (modern and faster)
./install.sh

The install.sh script uses uv for fast dependency resolution and installation.

πŸš€ Quick Start

πŸ€– Chat MCP Client

Interactive CLI interface to chat with LLMs (OpenAI, Ollama, Hyperbolic) connected to EASA regulations via MCP:

# Configuration
cp env.example .env
# Edit .env with your API keys

# Launch chat
python chat_mcp.py --provider ollama  # Local, no API key needed
python chat_mcp.py --provider openai  # With OpenAI
python chat_mcp.py --provider hyperbolic  # With Hyperbolic

Features:

  • πŸ’¬ Interactive chat with streaming responses
  • πŸ”§ Automatic function calling to EASA MCP server
  • πŸ” Search, retrieval and regulatory compliance validation
  • 🌐 Multi-provider support (OpenAI, local Ollama, Hyperbolic)

πŸ‘‰ Complete Chat MCP Guide

🎯 CrewAI Compliance Validator (NEW!)

Automated compliance audit with a team of 2 AI agents (Auditor + QA Challenger) that collaborate and challenge each other:

# Configuration (same .env as for chat)
cp env.example .env

# Audit a text
python compliance_crew.py \
  --text "Flight crew members must not exceed 900 hours" \
  --output report.md \
  --provider openai

# Audit a file
python compliance_crew.py \
  --file operations_manual.txt \
  --output compliance_report.md \
  --provider openai

# Interactive mode
python compliance_crew.py --interactive --output report.md

Features:

  • πŸ€– 2 specialized agents: Expert Auditor + QA Challenger
  • βœ… Cross-validation: QA challenges and verifies findings
  • πŸ“‹ Detailed Markdown report with exact EASA references
  • πŸ” Non-compliance identification with severity levels
  • πŸ”§ Full access to EASA MCP tools for agents
  • 🌐 Multi-provider support (recommended: OpenAI GPT-4)

πŸ‘‰ Complete CrewAI Compliance Guide

πŸ“Š Building the Embeddings Database

The script supports two modes: single file or directory batch processing.

Single File Mode

# Parse a single XML file (3,357 topics)
python build_embeddings.py \
    --xml "Easy Access Rules for Air Operations - February 2025 - xml.xml" \
    --db easa_complete.db \
    --clear

# Parse only a specific category (e.g., ORO.FTL)
python build_embeddings.py \
    --xml "Easy Access Rules for Air Operations - February 2025 - xml.xml" \
    --category "ORO.FTL" \
    --db oro_ftl.db \
    --clear

# Parse only IR (Implementing Rules)
python build_embeddings.py \
    --xml "Easy Access Rules for Air Operations - February 2025 - xml.xml" \
    --types IR \
    --db easa_ir.db \
    --clear

Directory Batch Mode (NEW!)

Parse all XML files in a directory automatically:

# Parse all XML files in easy_access/ (default directory)
python build_embeddings.py \
    --db easa_complete.db \
    --clear

# Parse all XML files in a specific directory
python build_embeddings.py \
    --dir easy_access \
    --db easa_complete.db \
    --clear

# Parse all XML files with filters
python build_embeddings.py \
    --dir easy_access \
    --db easa_ir_only.db \
    --types IR \
    --clear

Features:

  • βœ… Automatically detects all .xml files in the directory
  • βœ… Processes files sequentially with progress tracking
  • βœ… Duplicate prevention (UNIQUE constraint on references)
  • βœ… Error handling per file (continues if one fails)
  • βœ… Detailed summary with statistics per file and final totals

Note: The build_embeddings.py script at the root is a convenient wrapper to the full implementation in easacompliance/scripts/build_embeddings.py. You can also use the module directly: python -m easacompliance.scripts.build_embeddings or python easacompliance/scripts/build_embeddings.py

πŸ” Semantic Search

# Interactive mode
python -m easacompliance.scripts.search_regulations \
    --db "easa_complete.db" \
    --interactive

# Single search
python -m easacompliance.scripts.search_regulations \
    --db "easa_complete.db" \
    --query "flight time limitations" \
    --top-k 5

# Manual compliance validation
python -m easacompliance.scripts.search_regulations \
    --db "easa_complete.db" \
    --manual "operations_manual.txt" \
    --top-k 10 \
    --min-score 0.3

Note: You can also use the direct path: python easacompliance/scripts/search_regulations.py

πŸ’» Python Usage

from easacompliance import EASAParser, EmbeddingsManager, TopicType

# Parser
parser = EASAParser("regulations.xml")

# Extract a specific topic
topic = parser.get_topic_by_reference("ORO.FTL.110")
print(f"{topic.reference} - {topic.title}")
print(f"Type: {topic.topic_type.value}")
print(f"Content: {topic.content}")

# Extract all topics from a category
oro_ftl_topics = parser.get_all_topics(pattern=r'^ORO\.FTL\.')
print(f"Found {len(oro_ftl_topics)} ORO.FTL topics")

# Semantic search
manager = EmbeddingsManager("easa_complete.db")
results = manager.search("flight time limitations", top_k=5)

for result in results:
    print(f"{result.reference}: {result.title} (score: {result.score:.3f})")

πŸ“ Project Structure

EASACompliance/              # Project root
β”œβ”€β”€ build_embeddings.py      # Build embeddings database (root script wrapper)
β”œβ”€β”€ chat_mcp.py              # Chat MCP client (root script)
β”œβ”€β”€ compliance_crew.py        # CrewAI compliance validator (root script)
β”œβ”€β”€ run_mcp_server.py        # MCP server launcher (root script)
β”œβ”€β”€ install.sh               # Installation script (uses uv)
β”œβ”€β”€ env.example              # Environment variables template
β”œβ”€β”€ requirements.txt          # Consolidated dependencies
β”‚
β”œβ”€β”€ easacompliance/          # Main package
β”‚   β”œβ”€β”€ __init__.py          # Public exports
β”‚   β”œβ”€β”€ parser.py            # EASA parser (EASAParser, Topic, TopicType)
β”‚   β”œβ”€β”€ embeddings.py        # Embeddings manager (EmbeddingsManager)
β”‚   └── scripts/             # CLI scripts
β”‚       β”œβ”€β”€ build_embeddings.py
β”‚       └── search_regulations.py
β”‚
β”œβ”€β”€ mcp_server_easa/          # MCP server package
β”‚   β”œβ”€β”€ server.py            # MCP server implementation
β”‚   β”œβ”€β”€ config.py            # Configuration
β”‚   β”œβ”€β”€ schemas.py           # Data schemas
β”‚   └── tools/               # MCP tools
β”‚       β”œβ”€β”€ search.py
β”‚       β”œβ”€β”€ retrieve.py
β”‚       β”œβ”€β”€ browse.py
β”‚       └── validate.py
β”‚
β”œβ”€β”€ tests/                   # Tests
β”‚   β”œβ”€β”€ test_embeddings.py
β”‚   β”œβ”€β”€ test_chat_setup.py
β”‚   └── test_crew_setup.py
β”‚
β”œβ”€β”€ docs/                    # Documentation
β”‚   β”œβ”€β”€ chat/                # Chat MCP documentation
β”‚   β”‚   β”œβ”€β”€ README.md
β”‚   β”‚   β”œβ”€β”€ QUICKSTART.md
β”‚   β”‚   └── IMPLEMENTATION.md
β”‚   β”œβ”€β”€ crew/                # CrewAI documentation
β”‚   β”‚   β”œβ”€β”€ README.md
β”‚   β”‚   └── IMPLEMENTATION.md
β”‚   β”œβ”€β”€ EMBEDDINGS_GUIDE.md
β”‚   └── ...
β”‚
β”œβ”€β”€ data/                    # Reference data
β”‚   └── EASA-eRules-XML-Export-Schema-1.0.0.xsd
β”‚
β”œβ”€β”€ README.md
β”œβ”€β”€ pyproject.toml
└── requirements.txt

πŸ“Š Statistics

The parser extracts 3,357+ structured topics from Air Operations documents:

Type Count Description
IR 1,025 Implementing Rules
AMC 1,263 Acceptable Means of Compliance
GM to IR 1,026 Guidance Material to Implementing Rules
CS 7 Certification Specifications
GM to CS 18 Guidance Material to Certification Specifications
Others 18 Easy Access Rules, disclaimers, etc.

Note: Additional topics are extracted from other EASA documents (Aircrew, etc.) when using batch processing mode.

πŸ”§ Filtering Options

All filtering options work in both single file and batch directory modes:

By category

--category "ORO.FTL"     # All ORO.FTL.*
--category "CS FTL"      # All CS FTL.*

By content type

--types IR               # Only Implementing Rules
--types IR AMC           # IR + AMC
--types ALL              # All (default)

By regulatory subject

--subject "Part-ORO"     # All Part-ORO
--subject "Part-CAT"     # All Part-CAT

By regex pattern

--pattern "ORO\\.FTL\\." # Custom pattern

Note: Filters are applied to all files when using batch mode (--dir).

πŸ“š Documentation

πŸ§ͺ Tests

# Run tests
python -m pytest tests/

# Or directly
python tests/test_embeddings.py
python tests/test_chat_setup.py
python tests/test_crew_setup.py

πŸ“ Changelog

See CHANGELOG.md for version history.

🀝 Contributing

Contributions are welcome! Feel free to open an issue or pull request.

πŸ“„ License

MIT License - See the LICENSE file for details.

πŸ™ Acknowledgments

  • EASA for the official XML schema
  • sentence-transformers for embeddings
  • The Python community for development tools

πŸ“§ Contact

For questions or suggestions, open an issue on GitHub.


Version: 2.0.0
Last updated: 2025

About

POC on the use of RAG, MCP and CrewAI to work on EASA regulations

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages