
How to Build a Text-to-SQL Agent with Python in 10 Minutes
You want to ask your database questions in plain English. Most tutorials make this harder than it needs to be — spinning up PostgreSQL, installing heavy ORMs, writing 200 lines of boilerplate. Here's a text-to-SQL agent in under 40 lines of Python. It uses PydanticAI for the agent logic and SQLite so you don't need any database server. The Code import sqlite3 import asyncio from pydantic_ai import Agent , RunContext , ModelRetry from pydantic import BaseModel from dataclasses import dataclass # 1. Set up a sample SQLite database conn = sqlite3 . connect ( " :memory: " ) conn . execute ( \ " \"\" CREATE TABLE employees ( id INTEGER PRIMARY KEY, name TEXT, department TEXT, salary INTEGER, hire_date TEXT ) \"\"\" ) conn.executemany( " INSERT INTO employees ( name , department , salary , hire_date ) VALUES ( ? , ? , ? , ? ) " , [ ( " Alice " , " Engineering " , 120000, " 2023 - 01 - 15 " ), ( " Bob " , " Marketing " , 85000, " 2023 - 06 - 01 " ), ( " Carol " , " Engineering " , 135000, " 2
Continue reading on Dev.to Tutorial
Opens in a new tab

![[Learning notes and hw] getting started with R-cnn: Manually implementing Intersection over Union (IoU)](/_next/image?url=https%3A%2F%2Fmedia2.dev.to%2Fdynamic%2Fimage%2Fwidth%3D800%252Cheight%3D%252Cfit%3Dscale-down%252Cgravity%3Dauto%252Cformat%3Dauto%2Fhttps%253A%252F%252Fdev-to-uploads.s3.amazonaws.com%252Fuploads%252Farticles%252Favit2emoxc0g68e5ltqj.jpg&w=1200&q=75)

