# debabratapruseth/ai-agent-with-llm-and-sql architecture

> Architecture diagram of the GitHub repository debabratapruseth/ai-agent-with-llm-and-sql, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/debabratapruseth/ai-agent-with-llm-and-sql
- Repository: https://github.com/debabratapruseth/ai-agent-with-llm-and-sql

## Overview

This notebook demonstrates a single user-to-result workflow: a natural-language question is translated by GPT-4 into SQL, checked for read-only safety, executed against SQLite, and formatted for display. The README describes these stages as one function; the graph separates them to show the documented workflow, not separate modules. Source excerpts were unavailable, so relationships reflect README documentation only.

Main entry points: [`AI Agent_LLM with SQL.ipynb`](https://github.com/debabratapruseth/ai-agent-with-llm-and-sql/blob/main/AI%20Agent_LLM%20with%20SQL.ipynb) (Assistant function)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_assistant["SQL assistant"]
  node_workflow["Assistant function"]
  node_validation["SQL validation"]
  node_execution["Query execution"]
  node_output["Result formatting"]
end

subgraph group_services["External services"]
  node_llm["GPT-4 API"]
  node_database[("SQLite database")]
end

node_user(("User"))

node_user -->|"asks"| node_workflow
node_workflow -->|"sends schema and question"| node_llm
node_llm -->|"returns SQL"| node_workflow
node_workflow -->|"checks SQL"| node_validation
node_validation -->|"allows safe query"| node_execution
node_execution -->|"runs query"| node_database
node_database -->|"returns rows"| node_execution
node_execution -->|"passes results"| node_output
node_output -->|"displays results"| node_user

click node_workflow "https://github.com/debabratapruseth/ai-agent-with-llm-and-sql/blob/main/AI%20Agent_LLM%20with%20SQL.ipynb"
click node_validation "https://github.com/debabratapruseth/ai-agent-with-llm-and-sql/blob/main/AI%20Agent_LLM%20with%20SQL.ipynb"
click node_execution "https://github.com/debabratapruseth/ai-agent-with-llm-and-sql/blob/main/AI%20Agent_LLM%20with%20SQL.ipynb"
click node_output "https://github.com/debabratapruseth/ai-agent-with-llm-and-sql/blob/main/AI%20Agent_LLM%20with%20SQL.ipynb"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_workflow,node_validation,node_execution,node_output,node_user toneBlue
class node_llm,node_database toneAmber
```

## Components

### SQL assistant

- [Assistant function](https://github.com/debabratapruseth/ai-agent-with-llm-and-sql/blob/main/AI%20Agent_LLM%20with%20SQL.ipynb): `AI Agent_LLM with SQL.ipynb`
- [SQL validation](https://github.com/debabratapruseth/ai-agent-with-llm-and-sql/blob/main/AI%20Agent_LLM%20with%20SQL.ipynb): `AI Agent_LLM with SQL.ipynb`
- [Query execution](https://github.com/debabratapruseth/ai-agent-with-llm-and-sql/blob/main/AI%20Agent_LLM%20with%20SQL.ipynb): `AI Agent_LLM with SQL.ipynb`
- [Result formatting](https://github.com/debabratapruseth/ai-agent-with-llm-and-sql/blob/main/AI%20Agent_LLM%20with%20SQL.ipynb): `AI Agent_LLM with SQL.ipynb`

### External services

- **GPT-4 API**
- **SQLite database**

### Other components

- **User**

## Connections

- User → Assistant function: asks
- Assistant function → GPT-4 API: sends schema and question
- GPT-4 API → Assistant function: returns SQL
- Assistant function → SQL validation: checks SQL
- SQL validation → Query execution: allows safe query
- Query execution → SQLite database: runs query
- SQLite database → Query execution: returns rows
- Query execution → Result formatting: passes results
- Result formatting → User: displays results
