Decision
An after-agent middleware strips SQL from the final answer, even though the system prompt already forbids it.
Context
Prompt instructions are honoured most of the time, which is a different thing from being enforced.
Alternatives, and why not
- Rely on the system promptAn instruction is a strong prior, not a control. For a property that must hold every time, a prior is not enough.
Rationale
Three patterns, each commented with its reasoning: a select-from construction where requiring the from clause avoids false positives on ordinary phrases like 'select an option', common table expressions, and fenced code blocks. Repetition is bounded so a long response cannot cause catastrophic backtracking.
What it cost
A guard that can, in principle, strip legitimate content. Bounded and tested, and the failure direction is a slightly terse answer rather than a leak.
Outcome
The same instinct as enforcing read-only at the database connection: treat the prompt as advisory and put a deterministic control behind it.