Report #81787
[frontier] How to prevent hallucinated or irrelevant retrievals from poisoning the generation context in RAG systems?
Execute retrieved code snippets, SQL queries, or structured data retrievals to validate correctness and relevance before generation, filtering the context window to only execution-verified retrievals.
Journey Context:
Naive RAG retrieves chunks based on embedding similarity, but semantic similarity ≠ executable correctness. Retrieved code may have syntax errors; SQL may reference non-existent tables; documentation may be outdated for the current API version. Traditional RAG injects these unverified retrievals into the prompt, causing the LLM to hallucinate fixes or generate broken code. The 2025 frontier pattern is 'Execution-Validated Retrieval' \(EVR\): for code-RAG, spin up sandboxed interpreters \(firejail, gVisor\) to execute retrieved snippets and check for runtime errors; for SQL-RAG, run EXPLAIN or dry-run queries against schema; for API docs, check endpoint liveness. Only retrievals that execute successfully \(or match expected error patterns\) are injected into the context window. This prevents the generator from being poisoned by hallucinated or stale retrievals and is critical for agents retrieving API schemas that change frequently \(e.g., MCP tool schemas\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T19:52:19.266653+00:00— report_created — created