The Idea
What if you could just ask your database a question in plain English — "how many orders came in last week from customers in Texas" — and get a real answer, without writing a single line of SQL? That's exactly what I built over a weekend using Amazon Bedrock, and it took less code than you'd expect.
The Problem With Traditional Dashboards
Every team has that one person who knows SQL well enough to answer ad-hoc data questions, and everyone else waits in line for them. Dashboards help, but they only answer the questions someone thought to build a chart for. The real bottleneck isn't the data — it's translating a human question into a query.
The Architecture
1. Bedrock as the Translator
A user's plain-English question gets sent to a Bedrock model with the database schema included in the prompt. The model's only job is to translate the question into a valid, safe SQL query — nothing else.
2. A Safety Layer Before Execution
This is the part people skip and shouldn't: before running anything, the generated query passes through a validation Lambda that blocks any DELETE, DROP, or UPDATE statements and enforces read-only access. The AI never touches your data directly — it only proposes a query a controlled function actually runs.
3. RDS or Aurora as the Data Source
The validated, read-only query runs against your existing RDS or Aurora database through a connection-pooled Lambda function, so you're not adding new infrastructure, just a smarter way to query what you already have.
4. Turning Results Back Into Plain English
The raw query result gets sent back to Bedrock one more time with a simple instruction: summarize this result in plain language. Instead of a raw table, the user gets a real sentence: "You had 342 orders from Texas last week, up 12% from the week before."
What Surprised Me
The hardest part wasn't the AI — it was the guardrails. Getting Bedrock to write correct SQL was surprisingly easy. Making sure it could never accidentally, or maliciously, damage real data took more thought than the actual query generation.
Try It Yourself
You don't need a huge dataset to test this. Spin up a small RDS instance, load a sample dataset like the classic Northwind database, and connect a single Lambda function to Bedrock. You can have a working prototype answering real questions in an afternoon.
This pattern isn't just a fun demo — it's genuinely useful for any team where non-technical people need real answers from data, without waiting on an engineer or learning SQL.
Loading article