Beyond Basic NLQ: Engineering Self-Correcting Data Agents with Oracle Select AI

Beyond Basic NLQ: Engineering Self-Correcting Data Agents with Oracle Select AI

How we built a system that verifies its own work to deliver data answers you can trust.

Natural Language Queries (NLQ) are no longer a novelty; asking systems "What were our total sales last quarter?" is becoming standard. The real challenge? Ensuring the answer is accurate, relevant, and derived from a true understanding of the user's intent. Simple Text-to-SQL often falls short, lacking the context and reasoning to handle ambiguity.

That’s why my colleague, Shahvaiz Janjua , and I moved beyond simple Q&A. We've focused on an agentic approach: building an intelligent system that doesn't just execute a query, but autonomously reasons about, verifies, and refines its own work until the result is correct.

At the core of this powerful architecture are Oracle solutions. We leveraged the capabilities of OCI GenAI services along with Oracle Autonomous Database 23ai and its native Select AI feature. For rapid demonstration purposes, we orchestrated the agentic logic using LangChain and built a simple UI with Gradio.

The True Innovation: An Agentic, Self-Correcting Workflow

Instead of a one-shot query, our system employs a cognitive loop, ensuring you get a reliable answer, not just a fast one.

Here is a visual breakdown of how this cognitive loop functions:

Article content

  1. Initial Query & Execution: The user asks a question. The agent uses Select AI within the Autonomous Database to instantly translate this into SQL and retrieve an initial dataset.
  2. Smart Verification: Here’s the critical step. The agent analyzes the database output. Using an LLM, it asks: "Does this data logically and completely answer the original human question?"
  3. Query Improvement: If the verification fails, the agent doesn't give up. It reasons about the gap and rephrases the original query for greater precision—turning "total sales last quarter" into a more specific "sum of revenue from all completed transactions for the period between [Date X] and [Date Y]."
  4. Repeat to Accuracy: The agent re-runs the improved query through Select AI, repeating the loop until the verification step passes.
  5. Verified Answer: Only once a high-quality result is confirmed is it translated back into a clear, human-friendly answer.

This structured reasoning makes the system robust and trustworthy, moving past the brittleness of basic NLQ.

The Powerhouse: Oracle's Data and AI Foundation

  • Oracle Autonomous Database 23ai with Select AI: This is the engine. Select AI’s native ability to translate natural language into optimized SQL directly within the database is a game-changer for performance and security. It seamlessly integrates with LLMs, including OCI Generative AI, to ensure high-quality SQL generation.

Want to dive deeper and see how to enable Select AI here?

  • OCI Generative AI: Provides the powerful LLMs that fuel both the Select AI translation and our agent's reasoning and rephrasing capabilities.

From Prototype to Production: The Road Ahead

While LangChain and Gradio were excellent for building this proof-of-concept, the goal is an enterprise-grade, Oracle-native solution. Our next step is to evolve this architecture by:

  • Replacing the external orchestration with the OCI AI Agents service to manage the stateful, multi-step workflow.
  • Building the user interface with Oracle APEX for a scalable, secure, and deeply integrated front-end experience.

Conclusion: A New Era of Trust in Conversational AI

By combining the native data intelligence of Oracle's Autonomous Database with a sophisticated agentic framework, we unlock a new level of reliability in conversational AI. This moves us past the novelty of Text-to-SQL and into a new era where we can build data analysis tools that we don't just use, but that we can fundamentally trust.

Try It Yourself

We believe in building in the open and encourage you to explore this architecture. We have published a sample implementation on GitHub that demonstrates the core agentic workflow, integration with OCI GenAI and Select AI, and the question refinement logic discussed in this post.

Access the complete code here: 🔗 https://github.com/mrakulji/agentic_selectai


About the Authors:

  • Shahvaiz Janjua is an AI Architect at Oracle's EMEA AI Center of Excellence. Passionate about making complex technologies accessible, he leverages deep technical expertise and extensive pre-sales experience to deliver impactful, cutting-edge AI solutions for real-world business challenges.
  • Mirjana Rakuljic is a Master Principal AI Architect at Oracle’s EMEA AI Centre of Excellence, focusing on AI and OCI technologies. With a deep understanding of data systems and AI integration, she is dedicated to building intelligent data platforms.

Thanks for sharing, Mirjana

Like
Reply

Simple but very smart! I was also impressed how you applied this to a Clinical Data Warehouse to enable Natural Language Scientific Queries directly into the database, potentially making a significant number of complex and expensive downstream systems obsolete! Great work Mirjana Rakuljic and Shahvaiz Janjua

Cristina Lemnaru

Principal AI Architect @ EMEA AI Center Of Excellence

10mo

That's really cool to see how you're using SelectAI and GenAI together. Love how it makes querying data so much easier and more accurate!

To view or add a comment, sign in

More articles by Mirjana Rakuljic

Others also viewed

Explore content categories