Skip to content

NiladriMallik/FastAPI-AI-Agent

Repository files navigation

Integrating FastAPI with AI-Agent

AI agent with FastAPI as the backend.

25/7/2025

  • 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-nano model, 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.

alt text

Next plan of action:

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

29/7/2025

HTML form receives a simple natural language query. Using regex, Javascript checks if the query contains DML command Home page to submit NL queries

  • If it is a DML command, user is redirected to another page asking for confirmation to execute DML query.

Confirmation page

  • 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.

Next plan of action

  • 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published