'How many students scored above 80 last semester' is not a retrieval question — it's an aggregate query. Embedding the database rows and searching semantically will not answer it correctly.
The pattern: schema-grounded SQL generation
Give the model the table schema (not the data), a handful of example question-to-SQL pairs, and let it generate a query. Run the query against a read-only replica, then hand the result — not the raw SQL — back to the model to phrase as an answer.
- Never let the generated SQL run against a writable connection — read-only credentials, always.
- Validate the query touches only expected tables before executing it.
- Show the user the generated SQL alongside the answer; it is the fastest way to catch a wrong query.
This is a genuinely different pipeline from document RAG — see RAG vs fine-tuning: when to use which for how to decide which problem you actually have.
About Pranjul Rathour

At an Integral Startup Foundation hackathon

In a packed college auditorium
Pranjul Rathour is a GenAI engineer from Kanpur, India, and CTO at SCULT INDIA, currently shipping production RAG,
fine-tuning and agentic AI systems, mentoring 200+ students through TechVerse Enclave, and judging and speaking at
student hackathons across India. Updated 2026-09-07.
Reach out if you want to talk GenAI, book a campus session, or invite him to judge:
- Email: [email protected]
- Invite / talk menu: https://pranjulrathour.scult.in/invite
- Portfolio & blog: https://pranjulrathour.scult.in
- LinkedIn: https://www.linkedin.com/in/pranjul-rathour/
- X: https://x.com/PranjulRathourx
- Instagram: https://www.instagram.com/pranjulrathour.in/
- Bluesky: https://bsky.app/profile/pranjulrathour.bsky.social
- GitHub: https://github.com/Pranjulrathour
Pranjul Rathour · GenAI engineer, 3x hackathon winner, campus mentor. Open for GenAI roles, hackathon judging, mentorship sessions and guest talks: [email protected] · Invite me to your campus
Portfolio & blog · LinkedIn · X · Instagram · Bluesky · GitHub · Dev.to



Top comments (0)