How py-why/pywhy-llm works
Project Type and Purpose
• PyWhy-LLM is an open-source Python library (no frontend) that augments causal analysis by driving Large Language Models (LLMs).
• Key functionality lives in three “Suggester” components (Model, Identification, Validation), which implement causal‐analysis operations by issuing prompts to an external LLM API.
Main Components
a. Client API Layer
• ModelSuggester, IdentificationSuggester, ValidationSuggester
• RelationshipStrategy enum
b. Core Protocol Interfaces
• protocols/estimator.py, identifier.py, modeler.py, validator.py
• Methods the Suggester implementations must expose
c. Prompt & Helper Modules
• prompts.py – prompt templates for each operation
• helpers.py – utility functions for building requests, parsing responses
d. Suggester Implementations
• suggesters/*.py – concrete classes implementing each protocol
e. External LLM Service
• OpenAI/GPT-4 or compatible LLM endpoint (not part of repo)
f. Documentation & Notebooks
• docs/ (Sphinx source, notebooks, Makefiles)
g. Testing
• tests/ – unit tests for each suggester via data providers
h. CI/CD
• .github/workflows/python-package.yml – linting, testing, packaging
i. Packaging
• pyproject.toml – project metadata, dependencies
Component Relationships & Data Flows
1. User Code → imports a Suggester class
2. Suggester → calls Helper to build a prompt
3. Helper → invokes LLM Adapter (HTTP client) → External LLM API
4. LLM API → returns response → Helper parses into Python objects
5. Suggester → returns suggestions to User
6. Tests → instantiate Suggesters with test LLM stubs → validate outputs
7. Docs builder (Sphinx) → reads source + notebooks → publishes HTML
Architectural Patterns & Principles
• Interface Segregation: clear protocols define boundaries between modules
• Layering: Presentation (API) → Business Logic (Suggesters, Protocols) → Infrastructure (Helper, LLM Adapter) → External Service
• Modularity: each “suggester” is interchangeable; new ones can be dropped in