learning-it by example

Back to the video

SQL Agent Guardrails: 8 Attacks Tested (DuckDB, Python)

A read only database stopped three of eight attacks on my SQL agent. The other five needed other layers.

Video #37 ยท AI agents and MCP

Steps in the video

  1. 0:00 Eight attacks
  2. 0:21 The idea
  3. 0:45 Setup
  4. 1:12 The data
  5. 1:24 Opening the database
  6. 1:43 The statement check
  7. 2:00 Limits
  8. 2:42 The attacks
  9. 4:00 What this does not show
  10. 4:30 Mistakes to avoid
  11. 4:51 My take and next steps
  12. 5:18 Recap

Files

  • agent.py (35 lines)
  • attack.py (62 lines)
  • guard.py (41 lines)
  • layers.py (53 lines)
  • shop.py (13 lines)

Download the code (zip)

Tested with

Python 3.12.15 | duckdb==2.0.0

What this does not show

The model is a stand-in that returns fixed SQL, so no real model is tested. Eight attacks, not every attack. DuckDB's settings are defence in depth, not a sandbox, and the timer is best effort. One DuckDB version, on Windows. The shop, the data and the secret file are made up.

Sources

Learning IT by Example.