Work effectively with AI coding agents. Understand them as language models running in a tool loop with limited context, which is why they guess, game the visible signal and report confidently. Recognise the shortcut and correctness tells in their code across Python, TypeScript/JavaScript, Rust, Java and Go, and know the damage each one does later. Verify changes instead of trusting them, review diffs fast for quality and security, judge when work is truly finished, and choose, design and steer tasks so agents can finish them well.
String-built SQL, shell commands and HTML card 4 of 6

SQL: from f-string to placeholder

builds on: Trust boundaries and untrusted input
The agent wrote the `-` lines. If someone sends `name` = `x' OR '1'='1`, the WHERE clause becomes always true and the query returns every user's email. In the `+` lines the value is handed to the driver separately from the SQL text, so the database never parses it as SQL. Each driver has its own placeholder syntax: `?` in sqlite3, `$1` in node-postgres, `%s` in psycopg. With psycopg the values still go in a separate tuple. The `%s` there is a marker for the driver, not Python's `%` operator.
// Python
--- a/app/users.py
+++ b/app/users.py
 def find_users(db, name):
-    q = (f"SELECT id, email FROM users "
-         f"WHERE name = '{name}'")
-    return db.execute(q).fetchall()
+    return db.execute(
+        "SELECT id, email FROM users "
+        "WHERE name = ?",
+        (name,),
+    ).fetchall()
Terms on this card
f-string
Python string literal prefixed with f, where {expr} is replaced by the expression's value when the string is built.
driver
The library your code uses to talk to a database. It sends the SQL and the values to the database and returns the rows.
sqlite3
Python's built-in SQLite driver. Its placeholder is ?.
node-postgres
The common Node.js driver for PostgreSQL. Its placeholders are $1, $2, and so on.
psycopg
The common Python driver for PostgreSQL. Its placeholder is %s, with values passed as a separate tuple.
Learn this step by step on Bytewise
Lesson goal: Spot injection risks in agent code: f-string or concatenated SQL, `shell=True` or `exec` with interpolated input, and `innerHTML` or unescaped templates. Replace each with parameterised queries, argument arrays or safe encoding. · the whole lesson