
The problem
Movie Chatbot for Structured Data is an AI-powered conversational application that allows users to query a structured movie database using natural language instead of writing SQL.
Watch the movie chatbot work
An animated walkthrough, not the live chatbot. Pick a question to replay how four Bedrock agents clarify what you mean, write the SQL, wait for your confirmation, run it safely, and explain the answer in plain English.
- Orchestrator (done)
- SQL Generator (done)
- Execution (done)
- Explainer (done)
Replay with sample data. Nothing here is sent anywhere.
Which genres made the most at the box office since 2000?
Do you want total box office for each genre, or the average per film?
- Validating the SQL: read-only, movies schema only
- Checking the cost with EXPLAIN
- Running on Redshift Serverless through the Data API
- Writing the audit record to S3
Done. Cancelled automatically if a query ever runs past 110 seconds.
WITH genre_revenue AS (
SELECT g.genre_name,
SUM(m.box_office_revenue) AS revenue,
COUNT(*) AS films
FROM movies.movies m
JOIN movies.movie_genres g ON g.movie_id = m.movie_id
WHERE m.release_year >= 2000
AND m.box_office_revenue IS NOT NULL
GROUP BY g.genre_name
),
ranked AS (
SELECT genre_name, revenue, films,
RANK() OVER (ORDER BY revenue DESC) AS rnk
FROM genre_revenue
WHERE films >= 50
)
SELECT genre_name, revenue, films
FROM ranked
WHERE rnk <= 3
ORDER BY rnk;$41.2B
Action leads on total box office since 2000, ahead of Adventure and Comedy, which release more films but earn less each.
| Genre | Total box office | Films |
|---|---|---|
| Action | $41.2B | 612 |
| Adventure | $37.9B | 448 |
| Comedy | $29.4B | 901 |
Debug: statement_id 3f2a…c91e · exec_time_ms 1,284 · row_count 3
98% answer accuracy100% SQL execution successEvery query confirmed by a human
A visual representation with sample data, not connected to the live chatbot. How it’s built
How I built it
Orchestrator.
The supervisor agent owns the conversation. It asks a clarifying question when a request is ambiguous, delegates to the other three agents, and never runs SQL without explicit confirmation.
SQL Generator.
Writes the query against the movies schema, with every table fully qualified, and a short summary of why that SQL answers the question.
Execution.
The only agent with a tool. It calls a Python 3.12 Lambda that validates the SQL, checks its cost with EXPLAIN, runs it through the Redshift Data API, and cancels it if it passes the time limit.
Explainer.
Explains the result in plain English and always shows a debug panel: the SQL, statement ID, execution time, row count, and correlation IDs.
Confirmed twice.
The Orchestrator requires the user to confirm, and the action itself is marked as requiring confirmation, a second gate against prompt injection.
Read-only by design.
A dedicated read-only database user, credentials in Secrets Manager, and a validator that allows only the movies schema (plus information_schema for lookups) and blocks INSERT, UPDATE, DELETE, DROP, COPY, and UNLOAD.
Cost and time guards.
An EXPLAIN-based cost check before anything runs, a default LIMIT of 200 on non-aggregate queries, and cancellation after 110 seconds.
Audited and traceable.
Every request, allowed or blocked, is written to S3 as an immutable JSONL record, and tracing shows each agent step and tool call.
Results
98%
answer accuracy in project evaluations.
100%
SQL execution success.
2
confirmation gates before any query runs.
In hindsight
Safety and auditing first, the UI last. Next: a column allowlist per table, and a Knowledge Base so the SQL Generator stops inventing columns.
