liveBook · Manning

Parameterized query

As explained in Generative AI in Action

A prepared statement is a parameterized database query whose SQL structure is defined separately from the supplied data values.

A parameterized query keeps SQL structure separate from supplied data values. This helps prevent user input or malicious LLM-generated SQL from changing the intended query. One attack example starts with a request to generate a report and produces SQL that could delete the users table. section 13.2.2

For database queries, use prepared statements alongside input and output validation, restricted database permissions, and regular audits. The term is also used for a prompt-injection safeguard: pass user input into a chatbot prompt using placeholders rather than concatenating it directly. These are related injection defenses, but apply to different inputs and systems. section 13.2.2 section 6.6

How Generative AI in Action covers it

How deep it goes
Recommends prepared statements and related safeguards, but provides no implementation steps or API details.
Examples
Uses a malicious report request that could produce DROP TABLE SQL and describes placeholders for chatbot input.
What you can do after
Apply prepared statements with validation, restricted database permissions, and audits to reduce risks from malicious generated SQL.
How it connects
Connects parameterized queries with SQL injection, prompt injection, input validation, database permissions, and secure software development.

Also explained in

Compare how 8 books explain parameterized query →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Generative AI in Action. The section links point to the parts of the book it draws on.