Why RAG copilots silently give wrong counts and how to fix the pipeline
A document-search copilot built on LangGraph and Bedrock confidently returned an incorrect document count to a user, stating 27 when the actual database total was 84. The discrepancy arose because the language model counted only the results visible in its context window, after retrieval caps, permission gates, and version deduplication had already reduced the dataset. A deeper code review revealed that a single shared state field, total_available_results, was being overwritten mid-pipeline, causing its meaning to shift from the true database total to the smaller surfaced card count. The fix involved preserving the authoritative database count in a dedicated, immutable state field that nothing downstream could overwrite. The incident highlights a broader design principle: LLMs should never compute aggregates such as counts or sums, as those answers must always come from the system of record.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in