Verifying AI-generated SQL queries in an agent system

Hey everyone, I need some advice on my AI project. I’m building a SQL agent using Agentic AI and I’m stuck on the validation part.

Here’s what my system does:

  1. Takes natural language input
  2. Checks SQL schema
  3. Makes sure schema is valid
  4. Uses AI to create SQL query
  5. Checks if query syntax is okay
  6. Makes sure it matches the original intent
  7. Runs the query
  8. Checks if results make sense
  9. Suggests fixes if needed

I’m not sure how to properly validate each step, especially the AI-generated stuff. Has anyone built something similar? What are some good ways to make sure everything is working right?

Any tips or ideas would be super helpful. Thanks!

yo, that’s a neat project! for validating ai queries, maybe try unit testing? create some mock data and expected results, then run ur ai-generated queries against it. also, consider using a query explain plan to check efficiency. what kinda safeguards u got against sql injection btw?

that’s a really cool project! have you considered using test cases to validate the ai-generated queries? you could create a set of sample inputs and expected outputs, then compare the ai’s results against those. it might help catch any weird edge cases. what kind of database are you using for this btw?

Your project sounds intriguing. For validation, consider implementing a multi-stage approach. First, use static analysis tools to check query syntax and structure. Then, employ dynamic testing with a sanitized dataset to verify query execution and result accuracy. Implementing a query complexity analyzer can help flag potentially problematic queries. Additionally, maintaining a log of generated queries and their outcomes can provide valuable insights for ongoing refinement. Have you explored using machine learning models to predict query performance and potential issues based on historical data? This could add an extra layer of validation to your system.