How to Train AI for Accurate SQL Queries, According to Sachin Rekhi

S

Sachin Rekhi

LinkedIn Author

Helping product managers master their craft in the age of AI | 3x Founder | ex-LinkedIn, Microsoft

In a recent LinkedIn post, Sachin Rekhi discusses a crucial challenge many businesses face today: how to trust AI-generated SQL queries without the risk of hallucinations. Rekhi, a prominent figure in the tech space, shares his practical strategies for ensuring AI accuracy, particularly when using tools like Claude, by emphasizing the importance of data-specific training.

Rekhi directly addresses the common concern about AI reliability, stating:

“Everyone asks: how do you trust AI to write SQL without hallucinating? Short answer: you don’t. Not until you teach it your data first.”

He clarifies that his own reliance on AI for SQL queries, having not written one himself in over a year, is a result of deliberate upfront investment in training the AI on his specific data environment. This approach, Rekhi argues, is key to overcoming the limitations of generic AI models.

The Power of Example-Based Learning

One of Rekhi’s core strategies revolves around providing the AI with real-world examples rather than just documentation or rules. He elaborates on this by explaining the effectiveness of feeding the AI actual queries that have been used for recent analyses.

According to Rekhi:

“Give it real examples. Not documentation, actual queries. Have your data team pull together recent analyses—the question in plain English and the SQL that answered it. I add these to a Claude Project (or a Claude Code skill if I’m using that). Claude learns by example better than it learns by rules, so it’ll replicate the patterns.”

This method, Rekhi suggests, allows the AI to better understand and replicate the patterns and nuances present in the organization’s data and query structure, leading to more accurate and relevant results.

Addressing Database Schema Peculiarities

Rekhi also highlights the necessity of teaching AI about the unique quirks of a specific database schema. He notes that databases often contain columns that are misnamed, outdated, or simply confusing, which can lead AI astray.

To combat this, Rekhi advises:

“Teach it your schema’s weirdness. Every database has columns that are misnamed, deprecated, or just confusing. Tell Claude about them in the project instructions. Example: our signup_source table has a source column that’s full of junk and a canonical_source column that’s actually clean. I added one instruction—’use canonical_source, not source’—and it never messed up again.”

By explicitly instructing the AI on these anomalies, Rekhi demonstrates how to preemptively correct potential errors and ensure the AI consistently uses the correct data fields.

Fostering Team Collaboration and Consistency

Beyond individual training, Rekhi emphasizes the benefit of making AI training projects shared resources within a team. This collaborative approach, he argues, amplifies the benefits of accurate AI training across the entire organization.

As Rekhi points out:

“Make the Claude Project shared so your whole team can leverage each other’s work. Now the next team member doesn’t need to do anything to ensure accurate queries.”

This shared knowledge base not only saves time but also promotes consistency in data analysis across different team members. Rekhi concludes by sharing his personal experience of auditing queries initially to build confidence, a process that has now eliminated any second-guessing of AI-generated results.

📝 About This Content

This article is based on insights shared by Sachin Rekhi on LinkedIn.

📅 Originally posted on March 12, 2026 | View original post on LinkedIn →