feat: DSL API, ProviderConfig, hexagonal architecture improvements (0.2.0rc8)#31
Merged
luiscarbonel1991 merged 3 commits intoMar 23, 2026
Merged
Conversation
…gration tests - Add Pythonic DSL: nlp2sql.connect() -> .ask() / .validate() / .explain() / .suggest() - Add ProviderConfig: unified AI provider config (provider, api_key, model, temperature, max_tokens) - Add ExampleRepositoryPort: hexagonal port for few-shot examples (ExampleStore implements it) - Add QueryValidatorPort + RegexQueryValidator: deterministic SQL validation without LLM - Add QuerySafetyPort: extracted SQL safety checks from repositories to core - Extract sql_safety.py and sql_keywords.py from query_service.py to core/ - Unify storage: get_data_directory() with fallback chain (env > ./embeddings > ~/.nlp2sql/data) - Add per-database FAISS isolation: schema + examples indexes under <db_hash>/ - Add dimension validation to ExampleStore (prevents mock/real provider mismatch) - Update default models: gpt-4o-mini, claude-sonnet-4-20250514, gemini-2.0-flash - Wire ProviderConfig through factories (backward-compatible) - Add QueryResult dataclass with typed access (.sql, .confidence, .is_valid, .explanation) - Add conftest.py, 17 integration tests, 3 LLM smoke tests, llm pytest marker - Update README, API.md, ARCHITECTURE.md - Bump version to 0.2.0rc8
- Bump nlp2sql version from 0.2.0rc7 to 0.2.0rc8 in uv.lock. - Introduce a new CI workflow in .github/workflows/ci.yml for automated testing and linting on push and pull request events.
luiscarbonel1991
deleted the
feat/dsl-api-provider-config-hexagonal-ports
branch
March 23, 2026 03:38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Major architecture improvement: adds a Pythonic DSL API (
connect/ask), unifiedProviderConfig, 3 new hexagonal ports, unified storage with per-database isolation, and PostgreSQL integration tests.New Features
nlp2sql.connect(url, provider=ProviderConfig(...))returnsNLP2SQLclient with.ask(),.validate(),.explain(),.suggest()methods. Replaces verbosecreate_and_initialize_service()for common use casesprovider,api_key,model,temperature,max_tokens). Includesresolved_modelproperty that returns the effective model per providerExampleStore(FAISS) is now an adapter. Passexamples=[{...}]toconnect()for automatic setupcore/sql_safety.py(pure Python, no external deps).sql,.confidence,.is_valid,.explanation— replaces raw dict accessArchitecture Improvements
get_data_directory()inutils/storage.pywith fallback chain (NLP2SQL_DATA_DIR>./embeddings>~/.nlp2sql/data). BothSchemaEmbeddingManagerandExampleStoreshare the same base directory<db_hash>/embeddings/and<db_hash>/examples/preventing cross-contamination between databasesExampleStorevalidates FAISS index dimensions match the embedding provider on load (same pattern asSchemaEmbeddingManager)QueryGenerationServiceusesExampleRepositoryPort, notExampleStoredirectlysql_safety.py(safety checks) andsql_keywords.py(SQL keyword set) extracted fromquery_service.pytocore/AI Provider Updates
gpt-4o-mini(OpenAI),claude-sonnet-4-20250514(Anthropic),gemini-2.0-flash(Gemini)ProviderConfig. Backward-compatible — legacyai_provider+api_key+modelparams still workTests
uv run pytest -m "not integration and not llm"uv run pytest -m "integration and not llm"OPENAI_API_KEY=... uv run pytest -m llmuv run pytest -m integrationuv run pytest -m "not llm"New test files:
tests/conftest.py:MockAIProvider,MockEmbeddingProvider,postgres_availablefixture with Docker auto-detection, customizable viaNLP2SQL_TEST_POSTGRES_PORTtests/test_postgres_integration.py(7 tests): Repository connect, column discovery, view exclusion, safe query check, schema filters (include/exclude), embedding search with real schematests/test_dsl_integration.py(13 tests):connect()factory (5),ask()pipeline (3),validate()(2), LLM end-to-end with FAISS isolation viatmp_path(3)Documentation
connect,ask,validate,explain,suggest), ProviderConfig, QueryResultFiles Changed
Hexagonal Ports (9 total)
AIProviderPortSchemaRepositoryPortEmbeddingProviderPortExampleRepositoryPortQueryValidatorPortQuerySafetyPortSchemaStrategyPortCachePortQueryOptimizerPort