Your First AI Experiment: Run It Locally, Hassle-Free – Part 1 – Workflow Explanation
Most people think working with AI requires deep knowledge of machine learning, large language models, or cloud services. That’s not true—at least, not for your first experiment.
The goal of this blog is simple
- To give you a hands-on AI experience right on your personal computer—no cloud, no license, no complicated setup. You don’t need to be an AI expert or even know the fundamentals of ML or LLMs. Instead, we’ll jump straight into building a beginner-friendly AI agent that can talk to your database in plain English.
- This experiment is intentionally lightweight. You’ll see how an AI model can take natural language, translate it into SQL queries, run them on a real database, and return structured results—all through a simple Streamlit app.
- Of course, in real-world large-scale systems, implementing AI requires more: production-grade models, robust design, enterprise services, clean code, and a strong UI/UX. But before we get there, it’s important to first experience how easy it is to start experimenting with AI on a single PC.
This blog is your entry point. By the end, you’ll have built your first working AI agent—something you can try, modify, and learn from—without touching the cloud or paying for a license.
- Title: Natural Language Querying of SQL Server using Agentic AI (Ollama + Streamlit)
- Environment: Windows PC (SQL Server already installed)
- Goal: Build a simple Streamlit app where users type questions in plain English, and the app uses a local AI model to convert it into SQL, run it, and show results.
Expected AI Workflow Explanation (Step by Step):
- 1. User Query the Streamlit Web App: The journey starts with the user. They open a simple website (built with Streamlit) and type a question in plain English, such as:
- “What is the capital of India?” (General Knowledge)
- “Show me all customers from New York with more than one insurance policy.” (Database-Related)
- 2. Internally triggers “User Query Understanding”: Once the user submits the question, the system doesn’t directly jump to answering. Instead, it first activates an internal process that tries to “understand” what type of question this is.
- 3. Keyword Detection (Intent Classification): The AI Agent now plays detective. It looks at the keywords in the question and tries to figure out the intent:
- Is this a general knowledge question? (“What is the capital of India?”)
- Or is this a database-related question that needs real data from our SQL Server? (“Show me all customers from New York…”)
- 4. Two Paths Based on the Query: Depending on the intent, the query flows into one of two pipelines:
- General Query Path → for common, knowledge-based questions.
- Database Query Path → for questions that require pulling actual business data from the SQL database.
- 5. Prompt Construction: Once the path is chosen, the system prepares instructions (a prompt) for the AI model. Think of a prompt as a “well-written request letter” to the AI.
- 6. Build Simple or SQL-Specific Prompt
- If it’s a General Query, the prompt is short and direct (e.g., “Answer the following general knowledge question…”).
- If it’s a Database Query, the prompt includes extra context such as the database schema and metadata, so the AI knows how to frame the SQL code correctly.
- 7. Send Prompt to LLM: This carefully written prompt is sent to a Large Language Model (LLM), like a powerful AI brain (LLaMA in this case), which interprets and prepares the response.
- 8. LLM Prepares the Answer: The AI brain now works on the query:
- For General Queries → it produces a direct answer in plain English.
- For Database Queries → it creates an SQL query to fetch the right information.
- 9. AI Agent Receives LLM Response: The AI Agent gets the answer back. If it’s general text, that’s easy. But if it’s SQL code, some extra steps are needed before showing results.
- 9.A. Clean SQL: Sometimes the AI adds extra words like “Here is your query: …” which won’t work in the database. The Agent carefully cleans this so only the valid SQL statement remains.
- 9.B. Connect to SQL Server: The Agent then connects to the actual SQL Server database where the actual data is stored.
- 9.C. Execute SQL Query: It runs the cleaned SQL code against the database.
- 9.D. Retrieve Results: The raw data comes back from the database, but it’s usually not user-friendly.
- 9.E. Format Results: The Agent uses “Pandas” framework to neatly format the results into a readable table.
- 9.F. Send results back to the Web UI: Send the prepared results data to the web UI
- 10. Display Final Answer on Web UI: Finally, whether it is a general knowledge answer or database query results, the system sends the final output back to the web page. The user sees a clear, easy-to-read answer or a table — ready to analyze, without needing to know any coding or SQL.
Implementation Workflow
- Prepare Your Database
- Install or use an existing SQL Server database.
- Run the provided SQL script to create a schema and load some sample data (e.g., customers, policies).
- Set Up Your AI Agent
- Install Ollama to run a local large language model (LLM).
- We’ll use LLaMA 3, a free and open LLM, running completely on your PC (no internet or cloud required).
- Build the Backend Logic: Write a Python program that connects three things:
- Your SQL Server database
- The LLaMA 3 model (via Ollama)
- A web interface (Streamlit)
- Design the Web App
- Use Streamlit to create a simple web application where you type questions in plain English.
- Example: “Show customers from New York who purchased more than 1 policy.”
- How the Query Flows
- Step 1: You type the question into the web app.
- Step 2: Agent code determines whether it is a General Knowledge Question or a Database related question.
- Step 3: The app sends your text to Ollama, which runs the LLaMA 3 model.
- Step 4: If it is a GK question, LLM answer will be displayed in the Streamlit UI and skips the remaining steps.
- Step 5: If it is SQL related, the LLM converts your question into a valid SQL query.
- Step 6: Python executes this query on SQL Server.
- Step 7: The results are displayed in the Streamlit UI in a nice table format.
- Run & Enjoy
- Everything runs locally on your PC.
- No cloud subscription, no license, no external API.





















Looking forward to part 2