AI agent with FastAPI as the backend.
-
FastAPI Swagger UI takes a simple query in natural language and performs the DB operation. Eg.
- Remove record from table with ID = 69.
- Show top 5 records from table ordered by column_name in ascending manner
- Updates column based on filtering a column value
- Execute a stored procedure.
-
Since I am using
gpt-4.1-nanomodel, the agent fails to understand or interpret requests more complex than a simple query. -
The natural language query is sent on Swagger UI, but the confirmation for executing DML queries is given via terminal input only. Swagger UI cannot add a follow up prompt after the request is sent, it does not support dynamic, multi step interactions.
Option 1 - Two separate endpoints - one for request, other for confirmation. Option 2 - Custom frontend UI with with FastAPI endpoint with
- HTML + JS
- React + Tailwind
HTML form receives a simple natural language query. Using regex, Javascript checks if the query contains DML command

- If it is a DML command, user is redirected to another page asking for confirmation to execute DML query.
- If confirmed, redirects to result page and DML query executed in database and logs the DML action in log file along with the date stamp and time stamp.
- If cancelled, returned to home page.
- Auto block DML queries without where clause.
- Add option to download result in any format, e.g., JSON or CSV.
- Add a cache system to return result from cache, instead of wasting API token again.
- Develop a clean UI for the different pages.

