Lion Cipher Lab

Secure a text-to-SQL agent against injection-driven data exfiltration

Why it matters

A text-to-SQL agent is one of the most requested LLM features in a business: a user types a question in plain English, the model writes the SQL, the app runs it against the database, and the answer comes back grounded in real data. It is also one of the easiest ways to hand an attacker your database. Two things are true at once and together they are dangerous: a language model cannot reliably tell YOUR instructions apart from instructions hidden in the text it is processing (that is prompt injection, OWASP's LLM01), and whatever SQL it emits will, in the naive build everyone writes first, be…

What you'll learn

Steps in this lab

  1. The hazard, in one breath
  2. Set up a free, key-free, offline environment
  3. Build the naive text-to-SQL agent (t2sql.py)
  4. Attack it: drive attacks-succeeded above zero (attack_naive.py)
  5. Why 'just tell the model not to touch other tables' is NOT a control
  6. Build the defense: read-only + a deny-by-default parse gate (append to t2sql.py)
  7. Re-run the exact attacks: attacks-succeeded to 0 (secure_demo.py, measure.py)
  8. Prove why each layer is necessary: read-only alone and parse-vs-grep (why_layers.py)
  9. Judgment: when a text-to-SQL agent is acceptable, and the stronger pattern
  10. What you built -- and the one sentence to keep

Open the full interactive lab →