AI Query Engine (LLM)
The AI Query Engine is the intelligence core of Billx-Agent. It translates your natural language prompt into a valid, executable SQL query using a Large Language Model (LLM) β currently powered by Gemini (via Agno SDK).
π What It Does
Understands the intent behind the user prompt
Analyzes your database schema
Selects or generates a relevant SQL query
Supports parameterized templates via reusable tools
Performs optional response refinement for natural answers
π§ Powered by Gemini (via Agno)
Your prompt is sent to a Gemini LLM instance with rich context including:
Table and column metadata
Example SQL tools (templates)
Your exact user query
π§° Tool Matching & Template Filling
Billx-Agent uses a tool-based architecture:
Admins can define reusable SQL templates like:
The AI selects the best-matching tool (if any) for a given prompt.
It extracts placeholder values (e.g. dates, limits) from the input.
It fills the template and produces executable SQL.
β οΈ If no matching tool is found, the LLM generates raw SQL based on schema only.
π§Ό Validation & Safety
The system checks for valid SQL syntax
Ensures itβs a read-only SELECT query
Guards against unsupported operations (INSERT, DROP, etc.)
π Output Example
π€ Summary Flow
You send:
"Show me total orders in March"AI receives:
Your prompt
Schema for
orderstableSQL templates (tools)
AI returns:
SQL statement
Used tool (if matched)
Parameters detected
Refined plain-English response (optional)
π This module powers both /chat and /audio-chat, enabling natural language querying at scale.
Last updated