How gcpdev/xpshacl works
Main Components
• Justification Tree Builder – Builds logical justification trees (module: justification_tree_builder.py) when violations occur.
• Violation Knowledge Graph (KG) – A persistent cache that stores violations’ signatures along with their explanations (module: violation_kg.py and violation_signature related modules).
• Explanation Generator – Uses a retrieval-augmented generation approach and large language models to produce natural language explanations (module: explanation_generator.py). It interacts with external LLM APIs (or local models via Ollama, as mentioned in the README).
• Main Entry Point – The main.py under the src/ directory ties these modules together by handling inputs and orchestrating the overall validation-explanation workflow.
Relationships and Data Flow
– “No Violation” leading directly to a Success Report.
– “Violation Details” flowing to both the Justification Tree Builder and the Context Retriever.
– “Violation Signature” being sent to the Violation KG for caching.
• How the Violation KG:
– Immediately returns an explanation if there’s a cache hit.
– Triggers the Explanation Generator if there’s a cache miss.
• That both the output of the Justification Tree Builder and the Context Retriever flow into the Explanation Generator.
Architectural Patterns and Design Principles
• Modularity, with each component (e.g., validation, justification tree construction, context retrieval, caching, and explanation generation) encapsulated in its own Python module.
• Use of a caching mechanism through the Violation KG that improves performance and ensures consistency.
• Integration of external services (different LLM APIs and possibly local LLMs via Ollama) which means that the Explanation Generator must support multiple LLM integrations.
Relevant Technologies and Frameworks
• Python (3.7+), as the core language.
• rdflib for RDF graph manipulation (especially in the synthetic data generator).
• SHACL for data validation.
• LLM APIs (e.g., OpenAI, Google Gemini, Anthropic’s Claude) as well as optional local processing via Ollama.
• Unit testing framework for the tests/ directory code.