learning-it by example

#37 AI agents and MCP 5.7 min

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.

1. What does the SQL agent video say about telling the model in the prompt to only read the database?
2. In the DuckDB SQL-agent demo (made-up shop, a stand-in model), how many of the eight attacks did the read-only database file stop, and how many did all the layers stop?
3. In the DuckDB SQL-agent demo, which single layer stopped the file-read attack on its own?
4. In the DuckDB SQL-agent demo, how does the statement check decide whether a query is allowed?
5. What does the video say about DuckDB's own settings as protection for real untrusted users?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. Read the attack table

    Copy the code folder first. Read the ATTACKS dictionary in attack.py, the layers in guard.py and the build function in shop.py. For the attack 'private column', say which layer stops it and why the other layers do not. DuckDB needs to be installed as in the video to run the code, so this is a reading task.

    A hint

    The agent's copy of the database has no email column at all.

  2. Shrink the row limit

    In guard.py change MAX_ROWS from 50 to 2. Predict what the first question in agent.py, the country with the most money, will print after the arrow, given that the video showed three countries before. Then run python agent.py if DuckDB is installed and compare. Run it in a fresh copy of the code folder, because agent.py cannot build agent.duckdb again once that file exists from an earlier run.

    A hint

    The run function uses fetchmany(MAX_ROWS).

  3. Add an update attack

    In attack.py add a new entry to ATTACKS, called 'update', with the SQL UPDATE orders SET amount = 0. Predict the three columns of the table for it: no guard, read-only and all layers. Then run python attack.py if DuckDB is installed and compare.

    A hint

    Think about which setups can change the file and which layer only allows a SELECT.

  4. Stack two statements in the agent

    In agent.py add a new question to SCRIPT, as the list ["SELECT 1; SELECT 2"] (one SQL text), then run python agent.py, which asks every question in SCRIPT. Run it in a fresh copy of the code folder, because agent.py cannot build agent.duckdb again once that file exists from an earlier run. Predict whether it is blocked and which message the verified attack table shows for a stacked statement. Run it if DuckDB is installed.

    A hint

    The stacked attack in the video was refused with 'exactly one statement allowed'.

These tasks are for you to try on your own machine. Nothing is checked or saved.

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.

Up next in AI agents and MCP

More in AI agents and MCP

All AI agents and MCP videos

Related videos