AI-powered data generation plugin for sqlseed
Project description
sqlseed-ai
AI-powered data generation plugin for sqlseed.
LLM-driven schema analysis, self-correcting config generation, and template pool assistance. Supports multiple backends: Google AI Studio (Gemma 4 Native Function Calling), LM Studio, Ollama, and any OpenAI-compatible API (OpenRouter, OpenAI, DeepSeek, etc.).
Installation
pip install sqlseed-ai
Quick Start
# Set API key (or use GOOGLE_API_KEY for Google AI Studio)
export SQLSEED_AI_API_KEY="your-api-key"
# Generate AI-suggested YAML config
sqlseed ai-suggest app.db --table users --output users.yaml
# With self-correction (3 rounds by default)
sqlseed ai-suggest app.db --table users --output users.yaml --verify
# Specify model (defaults to Gemma 4 26B via Google AI Studio)
sqlseed ai-suggest app.db --table users -o users.yaml --model gemma-4-26b-it
# Use local LM Studio
sqlseed ai-suggest app.db --table users -o users.yaml --backend lm_studio --model google/gemma-4-e4b
# Skip cache
sqlseed ai-suggest app.db --table users -o users.yaml --no-cache
Features
Schema Analyzer
SchemaAnalyzer extracts rich context from your database (columns, indexes, sample data, foreign keys, data distribution) and builds a structured prompt for LLM analysis. Returns column-level generation configs as JSON.
Self-Correcting Refiner
AiConfigRefiner validates LLM output against actual schema:
- LLM generates column config
- Refiner checks for unknown generators, type mismatches, expression errors
- If errors found, sends correction request back to LLM
- Up to 3 retry rounds, then raises
AISuggestionFailedError
Auto Model Selection
When using the google_ai_studio backend (default), the GemmaModel enum provides pre-configured Gemma 4 variants. The model is selected based on the backend:
- Google AI Studio: Defaults to
gemma-4-26b-it(recommended balance of quality and speed). - LM Studio / Ollama: User must specify a loaded model via
--modelorSQLSEED_AI_MODEL. - OpenAI-compatible (OpenRouter, DeepSeek, etc.): User must specify both
--modeland--base-url.
For OpenRouter free models, set:
export SQLSEED_AI_BACKEND=openai_compat
export SQLSEED_AI_BASE_URL=https://openrouter.ai/api/v1
export SQLSEED_AI_MODEL=<free-model-name>
Skip auto-selection by specifying --model or SQLSEED_AI_MODEL.
When using the google_ai_studio backend, the GemmaModel enum provides pre-configured Gemma 4 variants:
| Enum Value | Model ID | Description |
|---|---|---|
GemmaModel.GEMMA_4_2B |
gemma-4-2b |
Lightweight, fast inference |
GemmaModel.GEMMA_4_4B |
gemma-4-4b |
Balanced speed and quality |
GemmaModel.GEMMA_4_26B |
gemma-4-26b |
High quality, recommended |
GemmaModel.GEMMA_4_31B |
gemma-4-31b |
Best quality, largest model |
The AIBackend enum selects the API backend:
| Enum Value | Backend | Default Base URL |
|---|---|---|
AIBackend.GOOGLE_AI_STUDIO |
Google AI Studio | https://generativelanguage.googleapis.com/v1beta/openai/ |
AIBackend.LM_STUDIO |
LM Studio | http://localhost:1234/v1 |
AIBackend.OLLAMA |
Ollama | http://localhost:11434/v1 |
Template Pool
When sqlseed fills a table with skip_ai=False, the plugin pre-generates candidate values for columns that can't be mapped to a deterministic generator (via sqlseed_pre_generate_templates hook).
File Caching
AI configs cached in platform-specific cache directory (~/Library/Caches/sqlseed/ai_configs/ on macOS, ~/.cache/sqlseed/ai_configs/ on Linux, %LOCALAPPDATA%/sqlseed/ai_configs/ on Windows) with schema hash validation. Schema changes auto-invalidate cache. Use --no-cache to skip. Override with SQLSEED_CACHE_DIR environment variable.
Configuration
Environment Variables
| Variable | Fallback | Default | Description |
|---|---|---|---|
SQLSEED_AI_API_KEY |
OPENAI_API_KEY |
— | API key (required) |
SQLSEED_AI_BASE_URL |
OPENAI_BASE_URL |
(auto by backend) | API endpoint |
SQLSEED_AI_MODEL |
— | gemma-4-26b-it |
Model name |
SQLSEED_AI_TIMEOUT |
— | 60 |
API timeout (seconds) |
SQLSEED_AI_BACKEND |
— | google_ai_studio |
AI backend: google_ai_studio, lm_studio, ollama, openai_compat |
GOOGLE_API_KEY |
— | — | Google AI Studio API key (required when backend is google_ai_studio) |
CLI Options
--model, -m Model name (overrides auto-selection)
--api-key API key (overrides env)
--base-url API base URL (overrides env)
--max-retries Self-correction rounds (default: 3, 0=disable)
--verify/--no-verify Toggle self-correction (default: verify)
--no-cache Skip file cache
--timeout API timeout in seconds (default: 120)
Plugin Hooks
This plugin registers via [project.entry-points."sqlseed"] and implements:
| Hook | Purpose |
|---|---|
sqlseed_ai_analyze_table |
LLM-driven table analysis, returns column configs |
sqlseed_pre_generate_templates |
Pre-generate candidate values for complex columns |
sqlseed_register_providers |
Placeholder (no-op, entry-point registration) |
sqlseed_register_column_mappers |
Placeholder (no-op, entry-point registration) |
Requirements
- Python >= 3.10
sqlseed >= 0.1.0openai >= 1.0google-generativeai >= 0.8- An OpenAI-compatible API key or Google AI Studio API key
Gemma 4 Integration
When using the google_ai_studio backend, sqlseed-ai leverages Gemma 4 Native Function Calling for structured schema analysis:
GEMMA_TOOLS
The plugin defines a GEMMA_TOOLS function declaration that tells Gemma 4 how to respond with structured column configs. Instead of parsing free-form text, the model is instructed to call a generate_column_config function with typed parameters (column name, generator, parameters, etc.), ensuring output conforms to the expected schema.
Native Function Calling Mechanism
- Tool Definition:
GEMMA_TOOLSdeclares agenerate_column_configfunction with a strict JSON Schema describing each parameter (column_name, generator_name, parameters, nullable, etc.). - Request: The schema context and analysis prompt are sent to the Gemma 4 model with
tools=[GEMMA_TOOLS]andtool_configset to force a function call. - Response Parsing: The model returns a
FunctionCallobject instead of plain text. The plugin extracts the structured args directly — no regex or fragile parsing needed. - Validation: The extracted args are passed through the same
AiConfigRefinerpipeline for self-correction.
This approach significantly improves reliability over text-based LLM output parsing, as the model is constrained to produce well-formed, schema-compliant responses.
License
AGPL-3.0-or-later
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlseed_ai-0.2.1.tar.gz.
File metadata
- Download URL: sqlseed_ai-0.2.1.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eacb35f21e23a0fd04ef04f07bfc7941c28e39dfb92ac58f4ac83a177cf2addb
|
|
| MD5 |
cbd104bd064c9ad6d0ff6908a98f0741
|
|
| BLAKE2b-256 |
e3c20c12d7dcc16c2c21212f36bd05026a71191c359c8f4b1eb50d4bbaa90f09
|
Provenance
The following attestation bundles were made for sqlseed_ai-0.2.1.tar.gz:
Publisher:
publish.yml on sunbos/sqlseed
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlseed_ai-0.2.1.tar.gz -
Subject digest:
eacb35f21e23a0fd04ef04f07bfc7941c28e39dfb92ac58f4ac83a177cf2addb - Sigstore transparency entry: 1753486423
- Sigstore integration time:
-
Permalink:
sunbos/sqlseed@4efb5f5cd3916864925383c118ebb6c97dcd04b8 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/sunbos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4efb5f5cd3916864925383c118ebb6c97dcd04b8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file sqlseed_ai-0.2.1-py3-none-any.whl.
File metadata
- Download URL: sqlseed_ai-0.2.1-py3-none-any.whl
- Upload date:
- Size: 22.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2560c38afbdca15f762abc2b7d62f5904b95d351b70c6963cd58417d9f6cc3bc
|
|
| MD5 |
8faaf423e8ae450d30d665e1d29ab5df
|
|
| BLAKE2b-256 |
f605d919445a3051c560e13cc9ec04edc60b9289c17baf864174d48b69732f7f
|
Provenance
The following attestation bundles were made for sqlseed_ai-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on sunbos/sqlseed
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlseed_ai-0.2.1-py3-none-any.whl -
Subject digest:
2560c38afbdca15f762abc2b7d62f5904b95d351b70c6963cd58417d9f6cc3bc - Sigstore transparency entry: 1753486438
- Sigstore integration time:
-
Permalink:
sunbos/sqlseed@4efb5f5cd3916864925383c118ebb6c97dcd04b8 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/sunbos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4efb5f5cd3916864925383c118ebb6c97dcd04b8 -
Trigger Event:
release
-
Statement type: