Generate SQL queries from natural language using LLMs
Built with Spring Boot β’ Powered by Groq β’ Production-ready architecture
SQL Generator AI is a backend service that transforms natural language queries into SQL statements using Large Language Models (LLMs) via Spring AI.
This project reflects real-world backend engineering practices including:
- Integration of modern LLM infrastructure in Spring Boot
- Clean and scalable layered architecture
- Effective prompt engineering with schema grounding
- Production-oriented API design
Client Request β REST Controller β Service Layer β Spring AI β Groq (LLaMA 3) β SQL Response
- The client sends a natural language query
- The backend enriches the prompt with a predefined schema
- The request is processed via Spring AI's
ChatClient - Groq LLM generates an optimized SQL query
- The API returns the SQL response
- Natural Language β SQL query generation
- Integration with Groq (LLaMA 3.3 70B model)
- Built using Spring AI ChatClient
- Clean controller-service architecture
- Schema-aware prompt design for higher accuracy
- Lightweight, extensible, and production-ready
sql-generator-ai/
β
βββ src/main/java/com/example/sqlgeneratorai/
β βββ controller/
β β βββ SqlController.java
β βββ service/
β β βββ SqlGeneratorService.java
β βββ dto/
β β βββ SqlRequest.java
β βββ SqlGeneratorAiApplication.java
β
βββ src/main/resources/
β βββ application.properties
β
βββ src/test/
βββ pom.xml
βββ mvnw- Language: Java 21
- Framework: Spring Boot
- AI Integration: Spring AI
- LLM Provider: Groq
- Model Used: LLaMA 3.3 (70B Versatile)
- API Style: RESTful APIs
- Build Tool: Maven
- Development Environment: VS Code
POST /api/sql/generate
{
"question": "Get all employees with salary greater than 50000"
}SELECT * FROM employees WHERE salary > 50000;The application uses a predefined schema to guide the model:
TABLE employees(
id BIGINT,
name VARCHAR(100),
salary DECIMAL,
department_id BIGINT
);- Improves SQL accuracy
- Reduces hallucinated queries
- Ensures schema consistency
Configure your application in application.properties:
spring.application.name=sql-generator-ai
spring.ai.openai.api-key=YOUR_API_KEY
spring.ai.openai.base-url=https://api.groq.com/openai
spring.ai.openai.chat.options.model=llama-3.3-70b-versatilegit clone https://github.com/SRCarlo/sql-generator-ai.git
cd sql-generator-aimvn clean installmvn spring-boot:runPOST http://localhost:8080/api/sql/generatemvn testController Layer
- Exposes REST endpoint
/api/sql/generate - Handles incoming HTTP requests
Service Layer
- Uses Spring AI
ChatClient - Injects schema into prompt
- Processes LLM response
DTO Layer
public record SqlRequest(String question) {}- Dynamic schema input support
- SQL validation and optimization layer
- Multi-database support (MySQL, PostgreSQL, etc.)
- Swagger / OpenAPI documentation
- Authentication & rate limiting
- Docker containerization
- Never expose API keys in source code
- Use environment variables or secret managers
- Implement request validation and rate limiting
Contributions are welcome!
git checkout -b feature/your-feature
git commit -m "feat: add your feature"
git push origin feature/your-featureThis project is licensed under the MIT License.
You are free to use, modify, and distribute this software with proper attribution.
Shubham Raut
Backend Developer | Java | Spring Boot | AI Integrations
If you found this project helpful:
- β Star the repository
- π΄ Fork the project
- π’ Share it with others
Built with β€οΈ using Spring AI and LLMs

