Agentic AI for self-service analytics: lessons from a BI project
Student teams at KMITL built BI agents for the same database. Query validation, schema context and deterministic Python made their answers faster and easier to verify.
Jan Kirenz · · 9 min read
Key takeaways
- Several teams built a BI agent for the same task: translate a business question into SQL, run the query, visualise the result and explain what it means.
- SQL validation, limits and retry loops made the systems more reliable.
- Loading the schema in advance, defining business metrics and supplying relevant business rules improved query quality more than increasing prompt length.
- Hybrid systems that used deterministic Python code had lower latency and gave the teams more control than pipelines run entirely by agents.
- The ability to inspect a result in the interface and test it against a known answer determined how useful each system was in practice.
A self-service analytics agent takes a question in everyday language, translates it into safe SQL and returns a table, a chart and an explanation of what the result means for the business. Each of those steps introduces a decision that can change the answer.
In a project at King Mongkut's Institute of Technology Ladkrabang (KMITL), several teams tackled the same business intelligence task in the agentic AI module of a management information systems course. Each team built a Python system that could answer questions about a complex Microsoft SQL Server database containing multiple tables. The system had to generate and execute a query, then return a table, a chart and an interpretation. The teams worked with Python, Google ADK with Gemini, Gradio, Microsoft SQL Server, GitHub and uv.
We wanted to find out which architectural decisions mattered when a system had to work safely, respond quickly and produce results that someone else could check.
1. What the teams found
Having several implementations of the same task under similar conditions made it possible to spot recurring patterns. The stronger systems combined carefully selected schema information, explicit SQL validation and deterministic code for tasks that required no language model. They displayed the query in the interface and tested the system on more than a single successful demonstration.
Different architectures worked. Some design choices consistently improved reliability, reduced latency and made it easier to trust an answer.
2. How the system checks SQL before execution
Generating the query is one part of a larger system. The stronger implementations used a separate validation step, restricted execution to SELECT-style queries, blocked risky keywords and set row limits and timeouts. The generated query remained visible in the interface.
This multi-agent pipeline validates the query and allows a retry before execution.
The most robust systems combined instructions in the prompt with rules enforced in code. They capped the number of rows, imposed query timeouts and enforced read-only queries. When a query failed at runtime, the validation loop passed the error back so the agent could correct it. An eloquent answer has little value if the underlying agent can execute unsafe SQL. Reliability depends on limiting what the model can do and making its actions verifiable.
3. Giving the model the context it needs
The largest gains came from improving the system’s understanding of the data model. Teams loaded schema information in advance, defined derived metrics in a semantic layer and specified which chart types suited which results. These steps resolved ambiguities before the agent generated SQL.
The system loads the schema once at startup. Later, visualisation and explanation can run in parallel.
A longer prompt does little for a model that lacks table relationships, naming conventions, business metrics or examples of permitted query patterns. Compact schema descriptions, annotated business rules and a selection of tables specific to each question had the greatest effect. In one documented implementation, preloading the schema alone saved about 1,500 tokens per request.
4. Where ordinary Python improved the agent
The most effective teams replaced agent steps with deterministic code wherever Python was faster and easier to control. Caching the schema, routing requests by rules, post-processing results in Python and sending straightforward cases down a shorter path consistently outperformed chains made up entirely of agents.
In this sequential design, Python executes the SQL and formats the result.
One team replaced two agent steps with Python and reduced the number of model calls from four to two. Another cut latency from 32.4 to 10.09 seconds by combining agent and code steps, adding fast paths and shortening its prompts. These results helped identify which parts of an analytics workflow actually benefit from model decisions.
5. Letting users verify an answer
People need to be able to trace a result back to its source. Systems earned trust when they showed the generated query, exposed the raw data, offered an export and explained why a particular chart had been chosen.
An exportable report brings together the question, SQL, result and business interpretation.
Some teams prioritised readability for managers. Others made the technical steps easier to inspect. Both approaches pointed to the same requirement. A BI agent is useful when people can verify its results and understand how it reached them.
6. Evaluation remains the hardest part
Teams tested their systems with benchmark questions, reference SQL and explicit checks on the written explanations. The failures were particularly informative. One benchmark reached 75% execution accuracy across 40 questions. The team documented errors caused by ambiguous schema information and rounding differences. On another team’s internal benchmark, the score rose from 2/10 to 10/10 after changes to the architecture. Using a model as a judge made reviews more systematic, although the underlying evaluation problem remained open.
7. Recommendations for analytics projects
The architecture determines which tasks the model handles, which tasks conventional software performs and how people see the results. Six decisions follow from the projects.
- Start with one narrow end-to-end task. Make the path from question to answer reliable before expanding it.
- Validate SQL before execution. Enforce limits and timeouts in code.
- Invest in schema information and business rules. Give the model the context needed to interpret the question.
- Take rule-based steps out of the model loop. Use deterministic code when a rule is sufficient.
- Show SQL, raw data, logs and errors in the interface. Make it possible to debug and verify the result from day one.
- Treat evaluation as a product feature. Maintain benchmark questions, reference queries and monitoring for the running system.
Conclusion
Self-service analytics with agentic AI is feasible. Once the system has to turn an everyday question into SQL, a chart and an explanation for managers, its architecture determines the quality and safety of the answer.
What struck me was how quickly the teams moved from an interest in AI agents to engineering decisions about validation, trade-offs, observability and user trust. Even in a course setting, the prototypes came close to real analytics products. The architecture behind the prompt made the difference between an impressive demo and a system that could bear scrutiny.
My thanks to the student teams for their prototypes, and to Assistant Professor Kanokwan Atchariyachanvanich and KMITL for the collaboration.