You can't prompt-inject a query the grammar can't express

Reddit r/AI_Agents Tools

Summary

The article describes an approach to prevent prompt injection attacks in AI agents by designing a query language that excludes destructive commands at the grammar level, making such attacks impossible.

Everyone's seen the stories by now — an agent gets confused or injected, and a production table is gone. The standard fix is a prompt: "never run destructive commands." That's a guardrail written in the same language the attacker gets to use. For our agent memory engine we moved the guarantee down a layer, into the grammar itself. In the query language, DELETE is not a token. Neither is ERASE, TRUNCATE, or GRANT. Those words lex as inert identifiers and the parser rejects them before anything dispatches. The only destructive statement that parses at all is FORGET <hash> — destroy exactly one record, named by its content hash. The rule underneath: destruction takes a hash, an identity, or an age. Never a predicate. There is no expressible sentence that means "delete everything matching X." GDPR erasure ("forget this person") and retention ("purge older than 90 days") still exist — but as separate host-side commands with their own gates, not sentences the query language can be talked into. It's three layers, because each fails differently: the lexer blocklist, a parser fast-reject with a dedicated error, and a per-process kill switch (--no-destructive-ops gives you a fully read-only session; on the server, even single-record FORGET needs admin scope). The thing that clicked for me while building it: "never delete" in a system prompt is a request. DELETE missing from the grammar is a fact. A prompt injection can't make a parser accept a sentence that doesn't exist. Honest limit: this protects the memory store, not arbitrary tools — hand your agent a bash tool and no grammar will save you. Repo link in the comments. Curious where others draw this line: do you sanitize agent-issued queries, point agents at read-only replicas, or push safety into the query surface itself?
Original Article

Similar Articles

Designing AI agents to resist prompt injection

OpenAI Blog

OpenAI publishes guidance on designing AI agents resistant to prompt injection attacks, arguing that modern attacks increasingly use social engineering tactics rather than simple string injections, and advocating for system-level defenses that constrain impact rather than relying solely on input filtering.

Understanding prompt injections: a frontier security challenge

OpenAI Blog

OpenAI publishes guidance on prompt injection attacks, a social engineering vulnerability where malicious instructions hidden in web content or documents can trick AI models into unintended actions. The company outlines its multi-layered defense strategy including instruction hierarchy research, automated red-teaming, and AI-powered monitoring systems.

Prompt Injection

Reddit r/AI_Agents

This article provides an overview of prompt injection in AI agents, mapping 11 papers and offering a reading list for newcomers to the field.

How are you detecting new prompt injection patterns after launch?

Reddit r/AI_Agents

The article discusses methods for detecting new prompt injection patterns in AI systems after launch, including semantic search, trace-level safety scores, and tools like Braintrust, while highlighting challenges with false positives and attack taxonomy.