liveBook · Manning

Fill-in-the-blank attack

As explained in Generative AI in Action

A fill-in-the-blank attack prompts a language model to reconstruct forbidden content from partial words or omitted segments.

A fill-in-the-blank attack is a prompt-injection technique that asks a language model to reconstruct forbidden content from partial words or omitted segments. It tests whether contextual completion bypasses the model’s restrictions. section 13.2.1

Partial-word completion test

Mark two prohibited words as X and Y, then ask the model to finish them from context. The demonstrated test uses Mistral’s Le Chat and displays only part of the generation. Treat the result as a security signal, not as a production interaction. section 13.2.1

Figure 13.7 Fill-in-the-middle prompt injection attack
figure

Inspect the supplied figure showing a fill-in-the-middle prompt-injection attack. section 13.2.1

Defensive handling requires validating and sanitizing model responses before passing them to backend functions, then encoding returned output to reduce unintended code execution. section 13.2.1

How Generative AI in Action covers it

How deep it goes
Defines the technique and demonstrates its prompt pattern, but does not explain model internals or systematic evaluation.
Examples
Uses forbidden words marked X and Y, a Mistral Le Chat test, and a fill-in-the-middle attack figure.
What you can do after
Diagnose model safeguards by running partial-word completion probes and validating outputs before downstream execution.
How it connects
Connects prompt injection with jailbreaking, Base64 encoding, response validation, sanitization, and output encoding.

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.