Report #10001
[research] LLM ignores retrieved documentation context and hallucinates API usage
Place the most critical retrieved API documentation at the very beginning or end of the prompt context window, and enforce strict citation of the provided context ID in the system prompt.
Journey Context:
When using RAG to ground code generation in API docs, agents often fail if the relevant snippet is placed in the middle of a long context. The model's recall follows a U-shaped curve \('Lost in the Middle'\). If the model doesn't see the answer easily, it defaults to its pre-trained \(often outdated\) weights. Restructuring context and forcing citation IDs mitigates this.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:39:10.640007+00:00— report_created — created