From Questions to Queries: How AI Agents Let You Talk to Your Data

This post is also available in: Deutsch

From user intent to SQL-powered insights – here’s how you can bring AI into your business intelligence workflow.

Meet Your New Sidekick: The AI Agent

Imagine asking your company’s database a question in plain English, and getting a real answer back in seconds. No SQL, no dashboards, no back-and-forth emails. Just insights. That’s the promise of AI agents, and it’s already within reach. In this article, I’ll show you how to build one using Azure, structured data, and a bit of prompt engineering magic.

We’ll use a fictional retail dataset to demonstrate how an AI agent can:

  • Understand natural language questions
  • Convert them into SQL
  • Return insights, fast

What Exactly Is an AI Agent?

AI agents are intelligent systems that interpret user input, process tasks autonomously or semi-autonomously, and respond with helpful output. In our context, the task is converting natural language into structured database queries.

You’ve Already Met One

  • Chatbots on websites
  • Voice assistants like Siri or Alexa
  • Email spam filters
  • Microsoft Copilot or Power BI Q&A

Why They Matter for Data Work

They break down the barrier between non-technical users and the data they rely; saving time, reducing dependency on analysts, and unlocking hidden value.

Sample Use Cases

Let us consider a retail company and what kind of questions they may have about their customers, products and employees. These are the kinds of natural-language queries an AI agent can handle:

  • “Which customers are likely to churn next month?”
  • “Top 10 selling products in Q2?”
  • “Employees overdue for compliance training?”
  • “Do millennial customers prefer eco-friendly products?”

We’ll walk through that last one in this article using a sample dataset.

Our Sample Dataset: Retail Customer Data

To demonstrate the full flow, we’ve created a fictional yet realistic dataset representing a retail loyalty system:

CustomerID AgeGroup Gender LoyaltyStatus EcoFriendlyPurchases LastPurchaseDate LoyaltyPoints
1001 25-34 Weiblich Gold 5 2024-05-20 800
1002 35-44 Male Silber 2 2024-04-18 300
1003 18-24 Weiblich Bronze 1 2024-03-10 150
1004 45-54 Male None 0 2024-01-05 100
1005 55+ Divers Gold 4 2024-04-01 950
1006 25-34 Weiblich Silber 3 2024-03-27 600
1007 35-44 Male None 0 2024-02-20 75
1008 18-24 Weiblich Bronze 2 2024-06-01 120
1009 25-34 Male Gold 6 2024-05-15 700
1010 35-44 Weiblich Silber 5 2024-04-30 450

Metadata:

Column Name Data Type Description
CustomerID Integer Unique identifier for the customer
AgeGroup Category Age bucket the customer falls into
Gender Category Gender of the customer
LoyaltyStatus Category Tier in the loyalty program
EcoFriendlyPurchases Integer Count of eco-friendly product purchases
LastPurchaseDate Date Date of most recent purchase
LoyaltyPoints Integer Points earned through purchases

Use Case: “Find customers aged 25–44 who have not purchased anything within the last 90 days

Let’s take a deeper look at how the AI agent handles this question from start to finish.

Step 1: Understanding the User Intent

The user provides a natural language prompt like:

Find our most loyal customers aged 25–44 who have not purchased anything within the last 90 days.

The AI agent receives this input and needs to:

  • Target Age Group
    • Filter customers where AgeGroup is ’25-34′ or ’35-44′.
  • Define Most Loyal Customers

Most loyal could mean:

  • Highest LoyaltyStatus (e.g. ‘Gold’)
  • Or highest LoyaltyPoints
    For this example, we’ll use LoyaltyStatus = ‘Gold’.
  • Exclude Recent Purchases
    • Remove any customers who made purchases in the past 90 days.

This is not just a keyword match—it involves real understanding of the query’s purpose.

Step 2: Passing It to the LLM with Context

The natural language question is passed to the Large Language Model (e.g. via Azure OpenAI), along with a prompt template that includes the schema and context:

You are an assistant that generates SQL queries based on user input. Generate a SQL query to answer the following request:

Find our most loyal customers aged 25–44 who have not purchased anything within the last 90 days.”

The inclusion of the schema ensures the LLM knows what data it can work with, much like giving it the blueprint of the database.

Step 3: LLM Generates the SQL

The LLM responds with a structured SQL query:

SELECT CustomerID,

       AgeGroup,

       LoyaltyStatus

FROM retail_customers

WHERE AgeGroup IN (’25-34′, ’35-44′)

  AND LoyaltyStatus = ‘Gold’

  AND LastPurchaseDate >= DATEADD(day, -90, GETDATE());

This query:

  • Extracts elects the customer with their age group and loyalty status
  • Filters for customers between a certain age range
  • Filters for customers or a particular loyalty status
  • Filters for customers who have not purchased any items within the last 90 days

Step 4: Query Execution

This SQL query is passed to the Azure SQL database (or Synapse, depending on your setup) using an API bridge like Azure Functions. The query runs and fetches the aggregated data.

Step 5: Returning the Result

The result set is then displayed to the user—either in a visual dashboard, conversational interface, or downloadable format. This way, the user receives meaningful insights without writing a single line of SQL.

Building the Architecture (Without Losing Your Mind)

Choosing Your Database Wisely

Azure has many options. Here’s how they stack up:

Database Best Use Case
SQL Database Classic relational queries & joins
Synapse Large-scale analytics & warehouse queries
Cosmos DB NoSQL use cases (not ideal for SQL joins)
Data Lake Raw unstructured files

Our choice? Azure SQL for relational data, simple joins, and business-readiness.

What If the Results Are Wrong?

This happens. Handle it like this:

  • Show the generated SQL
  • Ask: “Did this answer your question?”
  • Let users rephrase or tweak queries
  • Use feedback to retrain the prompt/LLM combo

Transparency builds trust—and improves the agent over time.

 Checklist to Go Live

  1. Prep & document your dataset 🧹
  2. Set up your Azure database 💾
  3. Deploy Azure OpenAI 🔍
  4. Build your API bridge with Azure Functions 🔧
  5. Validate sample queries 🧪
  6. Test the user interface 🧼
  7. Monitor usage & feedback 📊

Final Thoughts

Building an AI agent isn’t about replacing analysts. It’s about giving everyone access to insight—instantly. If you want to make structured data usable by everyone in your business, this is your starting point.

🚀 Need support along the way? Get in touch—we’d love to help you build your own AI-powered solution.

This post is also available in: Deutsch

Would you like to find out more about this topic? Then get in touch with us.

N°1
München

Ainmillerstr. 22
D-80801 München
Tel: +49 (0)89 45205420

N°2
Wien

Frankenberggasse 9/5
AT-1040 Wien
Tel: +49 (0)89 45205420

Follow us on Social Media

LinkedIn
Xing
Name(Required)
This field is for validation purposes and should be left unchanged.