# noahho/caafe architecture

> Architecture diagram of the GitHub repository noahho/caafe, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/noahho/caafe
- Repository: https://github.com/noahho/caafe

## Overview

1. **What this repository is**
   CAAFE is a Python package for semi-automated feature engineering on tabular datasets. The core architecture is a loop that takes a dataset plus a natural-language description, asks an LLM to propose feature code, executes the code under restrictions, and keeps only features that improve downstream model performance.

2. **Main public entry point**
   The main user-facing object is `CAAFEClassifier` in `caafe/caafe.py`, exposed through the package root. It behaves like a classifier wrapper: users provide a base sklearn-compatible model, an LLM choice, and iteration count; CAAFE then manages feature generation and model fitting around that estimator.

3. **Feature-engineering pipeline**
   The central data flow is:
   raw pandas data → preprocessing/encoding → prompt construction from dataset description → LLM-generated feature code → code execution → candidate feature matrix → cross-validated evaluation → accepted features appended to the training set.
   This loop is iterative, so the system can refine feature proposals using feedback from prior verification results.

4. **LLM code generation boundary**
   `caafe/run_llm_code.py` is the execution boundary for model-generated code. The README makes clear that CAAFE does not trust arbitrary code: generated Python is syntactically checked and constrained by a whitelist of allowed operations. This is the main safety boundary between untrusted LLM output and the Python runtime.

5. **Classifier abstraction boundary**
   `caafe/sklearn_wrapper.py` adapts downstream estimators to the CAAFE workflow. The downstream model must be fast and sklearn-like because it is repeatedly trained during feature verification. The repo explicitly supports models such as `TabPFNClassifier` and `RandomForestClassifier`, but the architectural requirement is “fit/predict like sklearn.”

6. **Data preprocessing and feature handling**
   `caafe/preprocessing.py` and `caafe/data.py` handle dataset preparation and likely dataset-specific utilities needed before prompting or model training. These modules form the boundary between raw tabular inputs and the feature-engineering loop, ensuring the data can be presented consistently to the LLM and the verifier.

7. **Evaluation subsystem**
   `caafe/evaluate.py`, `caafe/caafe_evaluate.py`, `caafe/metrics.py`, and `caafe/plotting.py` support benchmarking and reporting. This part of the repository is separate from the interactive classifier workflow and is used to compare generated features, run experiments across datasets, compute metrics, and visualize results.

8. **Baselines and comparison methods**
   `caafe/feature_extension_baselines.py` indicates a comparison layer for non-LLM feature engineering baselines. Architecturally, this keeps the repo from being only an LLM demo; it also supports method comparison for experiments and paper reproduction.

9. **Repository data assets**
   The `data/` directory contains the experimental corpus: human-written dataset descriptions, many prompt/code pairs under `generated_code/`, and `evaluations.zip`. These assets are not runtime dependencies for the core API, but they are important for reproducing experiments, inspecting generated feature proposals, and evaluating results across multiple datasets.

10. **Experiment scripts**
   `scripts/generate_features_script.py` and `scripts/run_classifiers_script.py` suggest a batch-oriented workflow for reproducing the paper’s experiments. One script likely generates feature code over datasets; the other runs downstream classifiers on the resulting engineered data.

11. **Testing and package boundary**
   The repo has a small test surface in `tests/test_sklearn_wrapper.py`, which points to `sklearn_wrapper.py` as a critical integration boundary. `setup.py` and the package layout indicate this is a distributable Python library rather than a standalone application.

12. **External services and runtime dependencies**
   The main external runtime dependency is an LLM endpoint, such as OpenAI GPT-4/GPT-3.5, used for feature-code generation. The architecture also relies on the Python scientific stack and sklearn-compatible estimators for repeated verification, making the whole system centered on pandas/tabular ML rather than web or service infrastructure.

Main entry points: [`caafe/caafe.py`](https://github.com/noahho/caafe/blob/main/caafe/caafe.py) (Feature loop), [`caafe/caafe_evaluate.py`](https://github.com/noahho/caafe/blob/main/caafe/caafe_evaluate.py) (CAAFE eval), [`caafe/run_llm_code.py`](https://github.com/noahho/caafe/blob/main/caafe/run_llm_code.py) (LLM code run), [`caafe/sklearn_wrapper.py`](https://github.com/noahho/caafe/blob/main/caafe/sklearn_wrapper.py) (Model wrapper)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core package"]
  node_pkg_root["Package API<br/>[__init__.py]"]
  node_caafe_classifier["CAAFEClassifier<br/>classifier wrapper<br/>[caafe.py]"]
  node_loop_orchestrator(("Feature loop<br/>pipeline core<br/>[caafe.py]"))
  node_preprocessing["Preprocessing<br/>tabular prep<br/>[preprocessing.py]"]
  node_data_utils["Data utils<br/>dataset helpers<br/>[data.py]"]
  node_prompt_codegen["Prompting<br/>llm prompt<br/>[caafe.py]"]
  node_llm_boundary{{"LLM code run<br/>safety boundary<br/>[run_llm_code.py]"}}
  node_wrapper["Model wrapper<br/>sklearn adapter<br/>[sklearn_wrapper.py]"]
end

subgraph group_eval["Evaluation"]
  node_evaluation_api["Eval entry<br/>benchmark runner<br/>[evaluate.py]"]
  node_caafe_evaluate["CAAFE eval<br/>experiment harness<br/>[caafe_evaluate.py]"]
  node_metrics["Metrics<br/>scoring<br/>[metrics.py]"]
  node_plotting["Plots<br/>reporting<br/>[plotting.py]"]
  node_baselines["Baselines<br/>comparison methods"]
end

subgraph group_assets["Data assets"]
  node_dataset_descriptions["Descriptions<br/>corpus"]
  node_generated_code["Generated code<br/>corpus"]
  node_evaluations_zip[("Eval archive<br/>results archive<br/>[evaluations.zip]")]
end

subgraph group_scripts["Scripts"]
  node_feature_script["Generate features<br/>batch script"]
  node_classifier_script["Run classifiers<br/>batch script"]
end

node_pkg_root -->|"exports"| node_caafe_classifier
node_caafe_classifier -->|"drives"| node_loop_orchestrator
node_loop_orchestrator -->|"prep"| node_preprocessing
node_loop_orchestrator -->|"reads"| node_data_utils
node_loop_orchestrator -->|"builds"| node_prompt_codegen
node_prompt_codegen -->|"uses"| node_dataset_descriptions
node_prompt_codegen -->|"requests code"| node_llm_boundary
node_llm_boundary -->|"stores"| node_generated_code
node_llm_boundary -->|"executes on"| node_wrapper
node_wrapper -->|"scores"| node_loop_orchestrator
node_loop_orchestrator -->|"appends features"| node_preprocessing
node_loop_orchestrator -->|"benchmarks"| node_evaluation_api
node_evaluation_api -->|"coordinates"| node_caafe_evaluate
node_caafe_evaluate -->|"computes"| node_metrics
node_caafe_evaluate -->|"visualizes"| node_plotting
node_caafe_evaluate -->|"compares"| node_baselines
node_feature_script -->|"produces"| node_generated_code
node_classifier_script -->|"reads results"| node_evaluations_zip

click node_pkg_root "https://github.com/noahho/caafe/blob/main/caafe/__init__.py"
click node_caafe_classifier "https://github.com/noahho/caafe/blob/main/caafe/caafe.py"
click node_loop_orchestrator "https://github.com/noahho/caafe/blob/main/caafe/caafe.py"
click node_preprocessing "https://github.com/noahho/caafe/blob/main/caafe/preprocessing.py"
click node_data_utils "https://github.com/noahho/caafe/blob/main/caafe/data.py"
click node_prompt_codegen "https://github.com/noahho/caafe/blob/main/caafe/caafe.py"
click node_llm_boundary "https://github.com/noahho/caafe/blob/main/caafe/run_llm_code.py"
click node_wrapper "https://github.com/noahho/caafe/blob/main/caafe/sklearn_wrapper.py"
click node_evaluation_api "https://github.com/noahho/caafe/blob/main/caafe/evaluate.py"
click node_caafe_evaluate "https://github.com/noahho/caafe/blob/main/caafe/caafe_evaluate.py"
click node_metrics "https://github.com/noahho/caafe/blob/main/caafe/metrics.py"
click node_plotting "https://github.com/noahho/caafe/blob/main/caafe/plotting.py"
click node_baselines "https://github.com/noahho/caafe/blob/main/caafe/feature_extension_baselines.py"
click node_dataset_descriptions "https://github.com/noahho/caafe/tree/main/data/dataset_descriptions"
click node_generated_code "https://github.com/noahho/caafe/tree/main/data/generated_code"
click node_evaluations_zip "https://github.com/noahho/caafe/blob/main/data/evaluations.zip"
click node_feature_script "https://github.com/noahho/caafe/blob/main/scripts/generate_features_script.py"
click node_classifier_script "https://github.com/noahho/caafe/blob/main/scripts/run_classifiers_script.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_pkg_root,node_caafe_classifier,node_loop_orchestrator,node_preprocessing,node_data_utils,node_prompt_codegen,node_llm_boundary,node_wrapper toneBlue
class node_evaluation_api,node_caafe_evaluate,node_metrics,node_plotting,node_baselines toneAmber
class node_dataset_descriptions,node_generated_code,node_evaluations_zip toneMint
class node_feature_script,node_classifier_script toneRose
```

## Components

### Core package

Public API and the feature-engineering loop

- [Package API](https://github.com/noahho/caafe/blob/main/caafe/__init__.py): module · Exports the library entry point · `caafe/__init__.py`
- [CAAFEClassifier](https://github.com/noahho/caafe/blob/main/caafe/caafe.py): classifier wrapper · User-facing estimator that orchestrates feature generation and fitting · `caafe/caafe.py`
- [Feature loop](https://github.com/noahho/caafe/blob/main/caafe/caafe.py): pipeline core · Iterative generate-evaluate-accept cycle · `caafe/caafe.py`
- [Preprocessing](https://github.com/noahho/caafe/blob/main/caafe/preprocessing.py): tabular prep · Cleans and encodes raw data for prompting and training · `caafe/preprocessing.py`
- [Data utils](https://github.com/noahho/caafe/blob/main/caafe/data.py): dataset helpers · Dataset-specific utilities and metadata handling · `caafe/data.py`
- [Prompting](https://github.com/noahho/caafe/blob/main/caafe/caafe.py): llm prompt · Constructs prompts from dataset descriptions and prior feedback · `caafe/caafe.py`
- [LLM code run](https://github.com/noahho/caafe/blob/main/caafe/run_llm_code.py): safety boundary · Validates and executes model-generated Python under restrictions · `caafe/run_llm_code.py`
- [Model wrapper](https://github.com/noahho/caafe/blob/main/caafe/sklearn_wrapper.py): sklearn adapter · Adapts downstream estimators to repeated fit/predict verification · `caafe/sklearn_wrapper.py`

### Evaluation

Benchmarking, metrics, and plots

- [Eval entry](https://github.com/noahho/caafe/blob/main/caafe/evaluate.py): benchmark runner · Runs experiments over datasets and models · `caafe/evaluate.py`
- [CAAFE eval](https://github.com/noahho/caafe/blob/main/caafe/caafe_evaluate.py): experiment harness · Evaluation workflow specific to CAAFE comparisons · `caafe/caafe_evaluate.py`
- [Metrics](https://github.com/noahho/caafe/blob/main/caafe/metrics.py): scoring · Computes performance and comparison metrics · `caafe/metrics.py`
- [Plots](https://github.com/noahho/caafe/blob/main/caafe/plotting.py): reporting · Visualizes evaluation results and comparisons · `caafe/plotting.py`
- [Baselines](https://github.com/noahho/caafe/blob/main/caafe/feature_extension_baselines.py): comparison methods · Non-LLM feature engineering baselines for experiments · `caafe/feature_extension_baselines.py`

### Data assets

Stored prompts, generated code, and dataset descriptions

- [Descriptions](https://github.com/noahho/caafe/tree/main/data/dataset_descriptions): corpus · Human-written dataset summaries used in prompts · `data/dataset_descriptions`
- [Generated code](https://github.com/noahho/caafe/tree/main/data/generated_code): corpus · Stored prompt/code pairs from feature generation runs · `data/generated_code`
- [Eval archive](https://github.com/noahho/caafe/blob/main/data/evaluations.zip): results archive · Packaged experimental outputs and results · `data/evaluations.zip`

### Scripts

Batch workflows for reproducing experiments

- [Generate features](https://github.com/noahho/caafe/blob/main/scripts/generate_features_script.py): batch script · Reproduces feature-generation runs across datasets · `scripts/generate_features_script.py`
- [Run classifiers](https://github.com/noahho/caafe/blob/main/scripts/run_classifiers_script.py): batch script · Runs downstream classifiers on engineered features · `scripts/run_classifiers_script.py`

## Connections

- Package API → CAAFEClassifier: exports · Package root exposes the main classifier wrapper
- CAAFEClassifier → Feature loop: drives · Wrapper coordinates the iterative feature-engineering loop
- Feature loop → Preprocessing: prep · Raw tabular data is normalized before prompting and training
- Feature loop → Data utils: reads · Dataset metadata and helpers feed the loop
- Feature loop → Prompting: builds · Creates prompts from data description and feedback
- Prompting → Descriptions: uses · Dataset descriptions ground the prompt context
- Prompting → LLM code run: requests code · Prompted model output becomes candidate feature code
- LLM code run → Generated code: stores · Prompt/code artifacts are preserved for inspection and reuse
- LLM code run → Model wrapper: executes on · Generated features are verified with sklearn-like estimators
- Model wrapper → Feature loop: scores · Downstream performance determines whether features are accepted
- Feature loop → Preprocessing: appends features · Accepted features are merged into the training matrix
- Feature loop → Eval entry: benchmarks · Feature sets can be evaluated in experiment mode
- Eval entry → CAAFE eval: coordinates · Evaluation entry point delegates to CAAFE-specific harnesses
- CAAFE eval → Metrics: computes · Experimental runs produce metrics
- CAAFE eval → Plots: visualizes · Results are summarized in plots
- CAAFE eval → Baselines: compares · LLM-generated features are measured against baselines
- Generate features → Generated code: produces · Batch generation writes prompt/code pairs
- Run classifiers → Eval archive: reads results · Classifier batch runs consume stored evaluation outputs
