liveBook · Manning

Sanitization

As explained in Generative AI in Action

Sanitization is the transformation or removal of unsafe content from input or output before it is processed or rendered.

Sanitization helps reduce risks when untrusted input reaches a language model or model-generated output reaches an application. It cannot eliminate prompt injection: models may treat instructions and external data alike. section 13.2.1 section 13.2.2

Reduce risk at the application boundary:

  • Give the model only the minimum access needed for its function. section 13.2.1
  • Validate input and output; use prepared statements for database queries, enforce database permissions, and audit frequently. section 13.2.2

Model-generated SQL

A request such as “Generate a report for users; DROP TABLE users” could lead to a query that deletes the users table if executed directly. Validate generated queries and use prepared statements rather than trusting model output. section 13.2.2

How Generative AI in Action covers it

How deep it goes
Identifies risks and safeguards, but does not specify a sanitization procedure or guarantee prevention.
Examples
Uses an embedded script-tag input and a report request that could generate SQL to drop a database table.
What you can do after
Apply it by validating input and output, using prepared statements, limiting database permissions, and auditing frequently.
How it connects
Connects prompt injection with retrieval-augmented generation, and insecure output with cross-site scripting and SQL injection.

Also explained in

Compare how 3 books explain sanitization →

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.