DEV Community

Cover image for From Plain English to SQL: Building Apps with AI Data Agents
Philip Ganchev
Philip Ganchev

Posted on

From Plain English to SQL: Building Apps with AI Data Agents

Ever found yourself bouncing between SQL IDE, BI dashboard, and spreadsheets just to answer one simple business question? Yeah, me too. That's exactly why I built Metric Moon - an app that lets you ask your data questions in plain English and get instant, visual answers.

"How many missions reached Mars each decade?"
↓ seconds later ↓
📊 Interactive bar chart + raw table + copyable SQL

The Magic Behind the Scenes: AI Data Agents

Here's what makes this possible - AI data agents. Think of them as your personal data analyst that never sleeps, never gets tired of your questions, and speaks both human and SQL fluently.

Image description

What Are AI Data Agents?

AI data agents are intelligent systems that can:

  • Know your data schema, table relationships, and business context
  • Generate optimized SQL queries that respect your database structure
  • Execute those queries against your database
  • Present results in the most meaningful way

The key difference from generic AI? These agents actually understand your data - they know which tables connect to which, what your columns mean, and how your business logic works. Instead of learning SQL syntax or figuring out which tables to join, you just ask questions like you would to a colleague.

Building Metric Moon: From Idea to Reality

I submitted Metric Moon to the Largest hackathon by Bolt, and let me tell you - AI data agents made the impossible possible in a hackathon timeline.

The Architecture

Frontend (React + TypeScript) 
    ↓
SkyAI Agent API
    ↓  
Database (Space Mission Data)
    ↓
Interactive Visualizations (Recharts)
Enter fullscreen mode Exit fullscreen mode

Key Features

🗣️ Natural Language Interface
No more remembering table names or SQL syntax. Just ask:

  • "Show me launch trends over time"
  • "What's the relationship between spacecraft mass and mission cost?"
  • "List all currently active missions"

🤖 Smart Visualization Selection
The agent doesn't just return data - it chooses the best chart type automatically:

  • Mission counts by destination → Pie chart
  • Trends over time → Line chart
  • Comparisons → Bar chart

🔍 Full Transparency
Users can see the generated SQL query, because trust is built on transparency.

How SkyAI Agents Made This Possible

The real star of the show is SkyAI Agents. The best part? SkySQL provides a no-code solution for creating data agents through their UI.

Creating Your Data Agent (No Code Required!)

1. Sign up for SkySQL
Create your SkySQL account to get started with AI-powered data agents
Go to SkySQL

2. Navigate to SkyAI Agents
Access the SkyAI Agents page from your SkySQL dashboard

3. Add your SQL datasource
Connect your database or data warehouse to SkySQL

4. Create an agent
Follow the on-screen steps to create your AI data agent

That's it! Your agent now has knowledge of the specific schema, tables, and columns you selected during setup, and can intelligently answer questions about that data.

Using Your Agent in Code

Once your agent is created, integration is incredibly simple.

const askQuestion = async (question, agentId) => {
  const response = await fetch('https://api.skysql.com/copilot/v1/chat', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-Key': YOUR_API_KEY
    },
    body: JSON.stringify({
      agent_id: agentId,
      prompt: question,
      config: {} // Optional configuration object
    })
  });

  const result = await response.json();

  return {
    prompt: result.prompt,
    answer: result.response.content,
    sql: result.response.sql_text,
    columns: result.response.col_keys,
    error: result.response.error_text
  };
};
Enter fullscreen mode Exit fullscreen mode

The API returns a structured response with:

  • content: The natural language answer
  • sql_text: The generated SQL query
  • col_keys: Column names from the query results
  • error_text: Any error messages if the query fails

For complete API documentation and examples, check out the SkySQL OpenAPI specification.

The Developer Experience

What amazed me most was how fast this was to build. Traditional approaches would require:

  • Setting up an LLM infrastructure
  • Building a query generation system
  • Implementing safety checks
  • Managing conversation context

With SkyAI agents, I focused on what matters - the user experience and visualization logic. The AI heavy lifting was handled by the platform.

Try It Yourself

Ready to build your own AI-powered data app? Here's how to get started:

  1. Get your API key from the SkySQL Portal
  2. Create a data agent with your database
  3. Start asking questions via the API

The SkyAI Agent API docs and OpenAPI specification have everything you need to get started.

The Future is Conversational

We're entering an era where the interface between humans and data isn't charts and dashboards - it's conversation. AI data agents are making this possible today, not tomorrow.

Your users shouldn't need to learn SQL to understand their data. They should just ask questions and get answers.

What would you build with AI data agents? Drop your ideas in the comments - I'd love to hear what problems you'd solve!


Want to see Metric Moon in action? Check out the demo. Built with SkyAI Agents, React, and a lot of curiosity about what's possible when AI meets data.

Top comments (0)