How magic-yuantian/pv-sql works
PV-SQL turns a natural-language question into SQL through database probing, constraint extraction, query generation, and verification with repair. Its main implementation is concentrated in pvsql/pv_sql.py, which uses a database environment and an injectable language model. The README also documents a batch benchmark runner. The workflow and adapter links are supported by the excerpts and README; no unsampled implementation details are assumed.
Main entry points: pv_sql.py SQL generation · db.py Database environment · llm.py LLM adapter · run_batch.py Batch runner
Components 12
SQL workflow
- Database probing
pvsql/pv_sql.py - Constraint extraction
pvsql/pv_sql.py - SQL generation
pvsql/pv_sql.py - Verify and repair
pvsql/pv_sql.py
Runtime adapters
- Database environment
pvsql/db.py - SQLite adapter
pvsql/db.py - LLM adapter
pvsql/llm.py
Batch execution
- Batch runner
scripts/run_batch.py
Other components
- Questioner
- SQLite database
- Chat model service
- Generated SQL
Connections 17
- Questioner → Database probing: asks question
README.md - Database probing → Database environment: executes probes
pvsql/pv_sql.py - Database probing → SQL generation: grounds query
README.md - Questioner → Constraint extraction: states requirements
README.md - Constraint extraction → SQL generation: supplies constraints
pvsql/pv_sql.py - SQL generation → Database environment: reads schema and samples
pvsql/pv_sql.py - SQL generation → Verify and repair: submits SQL
README.md - Verify and repair → Database environment: validates and executes
README.md - Verify and repair → SQL generation: requests repair
README.md - Verify and repair → Generated SQL: returns SQL
pvsql/pv_sql.py - SQLite adapter → SQLite database: queries
pvsql/db.py - Database environment → SQLite adapter: implemented by
README.md - SQL generation → LLM adapter: requests completion
pvsql/pv_sql.py - Verify and repair → LLM adapter: requests repair
pvsql/pv_sql.py - LLM adapter → Chat model service: sends chat request
pvsql/llm.py - Batch runner → Database probing: runs questions
scripts/run_batch.py - Batch runner → LLM adapter: tracks token usage
scripts/run_batch.py