dsllm - Domain Specific Language from LLM
Generate Domain Specific Language (DSL) statements from Natural Language input using Large Language Models (LLMs).
Overview
dsllm is a Python library that converts natural language descriptions into structured DSL statements. Currently supports SQL generation with OpenAI models, designed to be extensible to other DSLs and LLM providers.
Features
- SQL Generation: Convert natural language to SQL queries
- OpenAI Integration: Built-in support for GPT-3.5/4 models
- Context Injection: Support for database schemas and constraints
- Validation: Pre-flight and post-flight validation checks
- Safety Features: Read-only mode, dangerous operation detection
- Retry Mechanism: Automatic retries with exponential backoff
Installation
pip install dsllm
Quick Start
import asyncio
import os
from dsllm import DSLLMGenerator, OpenAIProvider, SQLGenerator
async def main():
# Initialize components
provider = OpenAIProvider(api_key=os.getenv("OPENAI_API_KEY"))
sql_generator = SQLGenerator()
generator = DSLLMGenerator(provider=provider, dsl_generator=sql_generator)
# Generate SQL from natural language
result = await generator.generate(
natural_language="Find all active users who registered this month",
context={
"schema": '''
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(255),
is_active BOOLEAN DEFAULT true,
created_at TIMESTAMP
);
'''
}
)
print("Generated SQL:")
print(result.dsl_statement)
# Run the example
asyncio.run(main())
Basic Usage
Simple Query Generation
result = await generator.generate("Show me all users")
print(result.dsl_statement) # SELECT * FROM users;
With Context and Constraints
result = await generator.generate(
"Find recent orders with high values",
context={"tables": ["orders", "customers"]},
constraints={"max_rows": 50}
)
Read-Only Mode
# Enable read-only mode for safety
sql_generator = SQLGenerator(enforce_read_only=True)
generator = DSLLMGenerator(provider=provider, dsl_generator=sql_generator)
# Only SELECT statements will be generated
result = await generator.generate("Get user data") # ✅ Works
result = await generator.generate("Delete old records") # ❌ Fails validation
Configuration
Environment Variables
OPENAI_API_KEY: Your OpenAI API key
Provider Options
provider = OpenAIProvider(
model="gpt-4", # Model to use
temperature=0.1, # Generation temperature
max_tokens=500 # Maximum tokens
)
Roadmap
- Additional DSLs: GraphQL, MongoDB queries, Elasticsearch DSL
- More LLM Providers: Anthropic Claude, Google PaLM, Azure OpenAI
- Advanced Features: Agentic loops, automated testing, observability
- Enhanced Validation: Semantic validation, performance analysis
Contributing
Contributions are welcome! Please see our Contributing Guide for details.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Frenk Dragar (@frenkd)
Metadata
Release files for dsllm 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dsllm-0.1.0.tar.gz | 17.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dsllm-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.8 kB
Release files / dsllm-0.1.0.tar.gz
| Download URL | dsllm-0.1.0.tar.gz |
|---|---|
| Size | 17.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e98982ec330caa3a388366fd532654b16bcf8b31b5fd101bc318a2c78a5f2720
|
|
BLAKE2b-256 checksum How to use checksums |
43f1194333bbb096139cbea14389d94caf613c2dc0a9ac2b27671df3a19e16cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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 Sep 1, 2025.
Transparency logRelease files / dsllm-0.1.0-py3-none-any.whl
| Download URL | dsllm-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7f4c39425ab348ddd7244beb457037a75f352adbd3c6e121d19aca71dd80c2df
|
|
BLAKE2b-256 checksum How to use checksums |
df8e39d26c7fbf993447dcee32cd092614ce7ed8be25177641e08058b45fec83
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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 Sep 1, 2025.
Transparency log