Skip to main content

ai-sql-reviewer

CLI-инструмент для schema-aware ревью изменённых PostgreSQL-запросов в CI.

Возможности

  • Извлекает изменённые statements из Git diff и сохраняет номера строк.
  • Проверяет синтаксис через SQLGlot до любых модельных вызовов.
  • Восстанавливает схему миграциями во временном PostgreSQL-контейнере.
  • Запускает независимые performance, architecture и correctness reviews, critic и final reviewer.
  • Валидирует все ответы Pydantic-моделями и показывает безопасные предложения как diff.
  • Поддерживает console, Markdown и JSON; исходные SQL-файлы не изменяет.
  • Публикует краткий GitHub PR summary и все inline findings одним review.

Требования

Python 3.12+, uv, Docker и доступный из shell migration command.

Установка

uv tool install ai-sql-reviewer==0.2.1

Конфигурация

dialect: postgres
migrations:
  command: ./scripts/migrate.sh
  postgres_version: "17"
  timeout_seconds: 120
llm:
  model: openai/example-model
  api_key_env: OPENAI_API_KEY
  api_base: null
  temperature: 0
  timeout_seconds: 60
  max_retries: 2
review:
  agents: [performance, architecture, correctness]
  minimum_confidence: 0.65
  max_findings: 10
output:
  format: markdown

Секрет хранится только в environment variable, имя которой задаёт api_key_env.

CLI

ai-sql-review review-diff --base origin/main --head HEAD --format markdown
ai-sql-review review-file path/to/query.sql --format console
ai-sql-review review-sql "SELECT * FROM users" --format json

--debug включает технические сообщения orchestration и parser без публикации внутренних model responses.

GitHub Actions

- uses: astral-sh/setup-uv@v9.0.0
- id: review
  continue-on-error: true
  env:
    OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
  run: uvx --from ai-sql-reviewer==0.2.1 ai-sql-review review-diff --base "${{ github.event.pull_request.base.sha }}" --head "${{ github.event.pull_request.head.sha }}" --format json > sql-review.json
- if: always()
  env:
    GITHUB_TOKEN: ${{ github.token }}
  run: uvx --from ai-sql-reviewer==0.2.1 ai-sql-review publish-github sql-review.json --base "${{ github.event.pull_request.base.sha }}" --head "${{ github.event.pull_request.head.sha }}" --repository "${{ github.repository }}" --pull-request "${{ github.event.pull_request.number }}"

Полный пример: examples/github-actions/sql-review.yml.

Ограничения MVP

  • Поддерживается только PostgreSQL и миграции, запускаемые одной shell-командой.
  • Нет GitHub App, query-plan execution и автоматического применения fixes.
  • Качество выводов зависит от выбранной через LiteLLM модели и предоставленной схемы.

Разработка

uv sync
uv run ruff check .
uv run mypy src
uv build

Metadata

Release files for ai-sql-reviewer 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ai-sql-reviewer 0.2.1
File Size Uploaded
ai_sql_reviewer-0.2.1.tar.gz 22.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ai-sql-reviewer 0.2.1
File Interpreter ABI Platform
ai_sql_reviewer-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 56.8 kB

Release files / ai_sql_reviewer-0.2.1.tar.gz

Download URL ai_sql_reviewer-0.2.1.tar.gz
Size 22.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6b81ad56441f4ca7501576c850179fc5b7cd98c044c7f7e6a2a1fdae0c4d9261
BLAKE2b-256 checksum
How to use checksums
293b384db23a0a0f91736252c2f921d5ef3046e2a47eb94cdb20b757ac6b412a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 3, 2026.

Transparency log

Release files / ai_sql_reviewer-0.2.1-py3-none-any.whl

Download URL ai_sql_reviewer-0.2.1-py3-none-any.whl
Size 34.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b5706d1bf05a72c947f22282f9053ee12838cffe802bad4dcdcde47ee7edc9a
BLAKE2b-256 checksum
How to use checksums
42c5e35f8f731e9d45eec390b7f13a788df9c0651cedbf01775a592bc3021854
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 3, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page