# hkustdial/nl2sql_handbook architecture

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

- Interactive diagram: https://gitdiagram.com/hkustdial/nl2sql_handbook
- Repository: https://github.com/hkustdial/nl2sql_handbook

## Overview

#### Purpose and Entry Points
This is a research handbook and curated knowledge base for Text-to-SQL/NL2SQL, accompanying TKDE 2025 and VLDB tutorials. Its primary entry point is `README.md`, which links readers to lifecycle guidance, method taxonomies, benchmark material, evaluation resources, papers, and slides. It is not an executable Text-to-SQL service; the only implementation is an offline Python benchmark-analysis utility under `src/dataset_analyze/`.

#### Knowledge and Publication Layer
The repository’s principal deliverable is static documentation and publication material:
- `README.md` is the navigation hub and curated paper/application index.
- `chapter/Pre_Processing.md`, `chapter/Translation_method.md`, and `chapter/Post_Processing.md` describe the model-facing pipeline stages.
- `TKDE_Survey.pdf`, `VLDB_Tutorial.pdf`, and `slides/NL2SQL-VLDB2025.pdf` are distributable survey/tutorial artifacts.
- `assets/` supplies diagrams referenced by the handbook, including lifecycle and benchmark timelines.

#### Text-to-SQL Lifecycle Taxonomy
The handbook organizes the problem space into connected stages rather than implementing them:
1. Input pre-processing: enriches natural-language questions with schema, instance, retrieval, or disambiguation context (`chapter/Pre_Processing.md`).
2. Translation: maps natural language plus database context to SQL (`chapter/Translation_method.md`).
3. Post-processing: refines, validates, repairs, or selects generated SQL (`chapter/Post_Processing.md`).
4. Benchmarking and data: characterizes datasets and their task properties (`chapter/Benchmark.md`).
5. Evaluation and error analysis: measures output quality and identifies failure causes (`chapter/Evaluation.md`, `chapter/Error_Analysis.md`).

These are conceptual boundaries; model training, inference, database execution, and LLM calls are delegated to externally linked projects.

#### Dataset Analysis Runtime
`src/dataset_analyze/analyze.py` is the practical analysis entry point. It coordinates dataset ingestion, SQL parsing, and report-oriented aggregation:
- `src/dataset_analyze/dataset.py` defines dataset-facing handling.
- `src/dataset_analyze/sql_parser.py` extracts SQL structure/features.
- `src/dataset_analyze/utils.py` provides shared support functions.

The expected flow is benchmark dataset input → dataset normalization/loading → SQL structural analysis → serialized benchmark report. Python is the material runtime implied by this code; no package manifest, service process, or deployment infrastructure appears in the tree.

#### Benchmark Report Corpus
`report/` stores precomputed JSON outputs, partitioned by benchmark. Each benchmark has an isolated report contract, e.g.:
- `report/Spider/report.json`
- `report/BIRD/report.json`
- `report/ATIS/report.json`

The corpus spans single-turn, multi-turn, multilingual, robustness, domain-specific, and realistic benchmarks. Reports are outputs/data assets rather than dynamically served API responses, and provide the concrete bridge between the analysis code and handbook claims.

#### External Boundaries
The project links to, but does not vendor, model and evaluation infrastructure. External dependencies include LLM training/deployment ecosystems (LitGPT, LLaMA-Factory), benchmark-specific evaluators (BIRD official evaluation, test-suite-sql-eval), and the separate NL2SQL360 testbed. External database engines, hosted LLM APIs, vector stores, and web infrastructure are not implemented or configured here.

#### Key Architectural Constraint
Treat this repository as a versioned documentation-plus-analysis artifact. Changes to benchmark logic should originate in `src/dataset_analyze/` and regenerate affected `report/*/report.json`; conceptual guidance belongs in `chapter/` and is surfaced through `README.md`. Avoid planning application runtime components unless intentionally expanding beyond the repository’s current scope.

Main entry points: [`README.md`](https://github.com/hkustdial/nl2sql_handbook/blob/main/README.md) (README hub), [`src/dataset_analyze/analyze.py`](https://github.com/hkustdial/nl2sql_handbook/blob/main/src/dataset_analyze/analyze.py) (Analysis coordinator), [`chapter/Translation_method.md`](https://github.com/hkustdial/nl2sql_handbook/blob/main/chapter/Translation_method.md) (Translation), [`chapter/Benchmark.md`](https://github.com/hkustdial/nl2sql_handbook/blob/main/chapter/Benchmark.md) (Benchmarking)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_handbook["Handbook taxonomy"]
  node_preprocessing["Pre-processing<br/>lifecycle guidance<br/>[Pre_Processing.md]"]
  node_translation["Translation<br/>lifecycle guidance"]
  node_postprocessing["Post-processing<br/>lifecycle guidance<br/>[Post_Processing.md]"]
  node_benchmarking["Benchmarking<br/>lifecycle guidance<br/>[Benchmark.md]"]
  node_evaluation["Evaluation<br/>lifecycle guidance<br/>[Evaluation.md]"]
  node_error_analysis["Error analysis<br/>lifecycle guidance<br/>[Error_Analysis.md]"]
end

subgraph group_analysis["Offline analysis"]
  node_analyze{{"Analysis coordinator<br/>Python entry point<br/>[analyze.py]"}}
  node_dataset["Dataset handling<br/>Python module<br/>[dataset.py]"]
  node_sql_parser["SQL feature parser<br/>Python module<br/>[sql_parser.py]"]
  node_utils["Shared utilities<br/>Python module<br/>[utils.py]"]
  node_benchmark_input[("Benchmark datasets<br/>external input")]
end

subgraph group_reports["Report corpus"]
  node_report_corpus[("Benchmark reports<br/>JSON corpus")]
  node_spider_report["Spider report<br/>JSON report<br/>[report.json]"]
  node_bird_report["BIRD report<br/>JSON report<br/>[report.json]"]
  node_atis_report["ATIS report<br/>JSON report<br/>[report.json]"]
end

node_readme["README hub<br/>documentation index<br/>[README.md]"]
node_publication_artifacts["Survey and tutorial artifacts<br/>publication PDFs<br/>[TKDE_Survey.pdf]"]
node_slides["VLDB slides<br/>tutorial slides"]
node_assets["Handbook diagrams<br/>visual assets<br/>[readme.md]"]
node_external_ecosystem["External model and eval tools<br/>external boundary"]

node_readme -->|"links"| node_preprocessing
node_readme -->|"links"| node_translation
node_readme -->|"links"| node_postprocessing
node_readme -->|"links"| node_benchmarking
node_readme -->|"links"| node_evaluation
node_readme -->|"links"| node_error_analysis
node_readme -->|"surfaces"| node_publication_artifacts
node_readme -->|"links"| node_slides
node_assets -.->|"illustrates"| node_readme
node_preprocessing -->|"conceptual input"| node_translation
node_translation -->|"generated SQL"| node_postprocessing
node_benchmarking -->|"benchmark basis"| node_evaluation
node_evaluation -->|"diagnoses"| node_error_analysis
node_benchmark_input -->|"loads"| node_dataset
node_dataset -->|"normalized data"| node_analyze
node_analyze -->|"parses SQL"| node_sql_parser
node_utils -.->|"supports"| node_analyze
node_sql_parser -->|"structural features"| node_analyze
node_analyze -->|"serializes reports"| node_report_corpus
node_report_corpus -->|"contains"| node_spider_report
node_report_corpus -->|"contains"| node_bird_report
node_report_corpus -->|"contains"| node_atis_report
node_report_corpus -.->|"informs claims"| node_benchmarking
node_readme -.->|"links externally"| node_external_ecosystem

click node_readme "https://github.com/hkustdial/nl2sql_handbook/blob/main/README.md"
click node_preprocessing "https://github.com/hkustdial/nl2sql_handbook/blob/main/chapter/Pre_Processing.md"
click node_translation "https://github.com/hkustdial/nl2sql_handbook/blob/main/chapter/Translation_method.md"
click node_postprocessing "https://github.com/hkustdial/nl2sql_handbook/blob/main/chapter/Post_Processing.md"
click node_benchmarking "https://github.com/hkustdial/nl2sql_handbook/blob/main/chapter/Benchmark.md"
click node_evaluation "https://github.com/hkustdial/nl2sql_handbook/blob/main/chapter/Evaluation.md"
click node_error_analysis "https://github.com/hkustdial/nl2sql_handbook/blob/main/chapter/Error_Analysis.md"
click node_publication_artifacts "https://github.com/hkustdial/nl2sql_handbook/blob/main/TKDE_Survey.pdf"
click node_slides "https://github.com/hkustdial/nl2sql_handbook/blob/main/slides/NL2SQL-VLDB2025.pdf"
click node_assets "https://github.com/hkustdial/nl2sql_handbook/blob/main/assets/readme.md"
click node_analyze "https://github.com/hkustdial/nl2sql_handbook/blob/main/src/dataset_analyze/analyze.py"
click node_dataset "https://github.com/hkustdial/nl2sql_handbook/blob/main/src/dataset_analyze/dataset.py"
click node_sql_parser "https://github.com/hkustdial/nl2sql_handbook/blob/main/src/dataset_analyze/sql_parser.py"
click node_utils "https://github.com/hkustdial/nl2sql_handbook/blob/main/src/dataset_analyze/utils.py"
click node_spider_report "https://github.com/hkustdial/nl2sql_handbook/blob/main/report/Spider/report.json"
click node_bird_report "https://github.com/hkustdial/nl2sql_handbook/blob/main/report/BIRD/report.json"
click node_atis_report "https://github.com/hkustdial/nl2sql_handbook/blob/main/report/ATIS/report.json"

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_preprocessing,node_translation,node_postprocessing,node_benchmarking,node_evaluation,node_error_analysis toneBlue
class node_analyze,node_dataset,node_sql_parser,node_utils,node_benchmark_input toneAmber
class node_report_corpus,node_spider_report,node_bird_report,node_atis_report toneMint
class node_readme,node_publication_artifacts,node_slides,node_assets,node_external_ecosystem toneNeutral
```

## Components

### Handbook taxonomy

Curated lifecycle guidance and research resources.

- [Pre-processing](https://github.com/hkustdial/nl2sql_handbook/blob/main/chapter/Pre_Processing.md): lifecycle guidance · Question and database-context enrichment. · `chapter/Pre_Processing.md`
- [Translation](https://github.com/hkustdial/nl2sql_handbook/blob/main/chapter/Translation_method.md): lifecycle guidance · Natural language and context mapped to SQL. · `chapter/Translation_method.md`
- [Post-processing](https://github.com/hkustdial/nl2sql_handbook/blob/main/chapter/Post_Processing.md): lifecycle guidance · Generated SQL validation, repair, and selection. · `chapter/Post_Processing.md`
- [Benchmarking](https://github.com/hkustdial/nl2sql_handbook/blob/main/chapter/Benchmark.md): lifecycle guidance · Dataset task properties and benchmark material. · `chapter/Benchmark.md`
- [Evaluation](https://github.com/hkustdial/nl2sql_handbook/blob/main/chapter/Evaluation.md): lifecycle guidance · Output-quality measurement. · `chapter/Evaluation.md`
- [Error analysis](https://github.com/hkustdial/nl2sql_handbook/blob/main/chapter/Error_Analysis.md): lifecycle guidance · Failure-cause analysis. · `chapter/Error_Analysis.md`

### Offline analysis

Python utility that derives benchmark characteristics.

- [Analysis coordinator](https://github.com/hkustdial/nl2sql_handbook/blob/main/src/dataset_analyze/analyze.py): Python entry point · Runs ingestion, SQL analysis, and report aggregation. · `src/dataset_analyze/analyze.py`
- [Dataset handling](https://github.com/hkustdial/nl2sql_handbook/blob/main/src/dataset_analyze/dataset.py): Python module · Loads and normalizes benchmark datasets. · `src/dataset_analyze/dataset.py`
- [SQL feature parser](https://github.com/hkustdial/nl2sql_handbook/blob/main/src/dataset_analyze/sql_parser.py): Python module · Extracts SQL structure and features. · `src/dataset_analyze/sql_parser.py`
- [Shared utilities](https://github.com/hkustdial/nl2sql_handbook/blob/main/src/dataset_analyze/utils.py): Python module · `src/dataset_analyze/utils.py`
- **Benchmark datasets**: external input · Source datasets supplied to offline analysis.

### Report corpus

Precomputed benchmark analysis outputs.

- **Benchmark reports**: JSON corpus · Versioned per-benchmark analysis results.
- [Spider report](https://github.com/hkustdial/nl2sql_handbook/blob/main/report/Spider/report.json): JSON report · `report/Spider/report.json`
- [BIRD report](https://github.com/hkustdial/nl2sql_handbook/blob/main/report/BIRD/report.json): JSON report · `report/BIRD/report.json`
- [ATIS report](https://github.com/hkustdial/nl2sql_handbook/blob/main/report/ATIS/report.json): JSON report · `report/ATIS/report.json`

### Other components

- [README hub](https://github.com/hkustdial/nl2sql_handbook/blob/main/README.md): documentation index · Primary navigation and curated resource index. · `README.md`
- [Survey and tutorial artifacts](https://github.com/hkustdial/nl2sql_handbook/blob/main/TKDE_Survey.pdf): publication PDFs · Distributable TKDE survey and VLDB tutorial materials. · `TKDE_Survey.pdf`
- [VLDB slides](https://github.com/hkustdial/nl2sql_handbook/blob/main/slides/NL2SQL-VLDB2025.pdf): tutorial slides · `slides/NL2SQL-VLDB2025.pdf`
- [Handbook diagrams](https://github.com/hkustdial/nl2sql_handbook/blob/main/assets/readme.md): visual assets · Lifecycle and benchmark timeline figures. · `assets/readme.md`
- **External model and eval tools**: external boundary · Linked training, evaluation, and NL2SQL360 projects are not vendored.

## Connections

- README hub → Pre-processing: links
- README hub → Translation: links
- README hub → Post-processing: links
- README hub → Benchmarking: links
- README hub → Evaluation: links
- README hub → Error analysis: links
- README hub → Survey and tutorial artifacts: surfaces
- README hub → VLDB slides: links
- Handbook diagrams → README hub: illustrates
- Pre-processing → Translation: conceptual input
- Translation → Post-processing: generated SQL
- Benchmarking → Evaluation: benchmark basis
- Evaluation → Error analysis: diagnoses
- Benchmark datasets → Dataset handling: loads
- Dataset handling → Analysis coordinator: normalized data
- Analysis coordinator → SQL feature parser: parses SQL
- Shared utilities → Analysis coordinator: supports
- SQL feature parser → Analysis coordinator: structural features
- Analysis coordinator → Benchmark reports: serializes reports
- Benchmark reports → Spider report: contains
- Benchmark reports → BIRD report: contains
- Benchmark reports → ATIS report: contains
- Benchmark reports → Benchmarking: informs claims
- README hub → External model and eval tools: links externally
