Command Palette

Search for a command to run...

Hectal
Phase 12: Advanced Patterns
RAG and Vector Search · Exercise 4 of 5 PreviousNext
Intermediate

Judge a generated SQL string

Write check_sql(sql, allowed) that returns "ok" or "rejected: <reason>". Never run anything: only inspect the text.

Rules, checked in this order: the text (after removing one trailing ;) must not contain ; (reason more than one statement); its first word, in lower case, must be select (reason only SELECT); the word after every from or join must be in allowed (reason table not allowed: <name>). Words are lower-case runs of letters, digits and underscores.

What Check tests

  1. A plain SELECT on an allowed table is ok
  2. A trailing semicolon is fine
  3. Other statements are rejected
  4. Two statements are rejected first
  5. Tables are checked after FROM and JOIN

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.