Why aggregate queries can expose sensitive data to AI agents

Community discussion Reddit r/LLMDevs · Individual views, not representative.

According to the Reddit community, aggregate queries are not a reliable safeguard for sensitive data when AI agents can query databases directly. A developer describes PostgreSQL access rules that initially allowed aggregates without approval, even though reading individual records required authorization.

The problem is that aggregate functions can reveal concrete values. MIN and MAX return values from the underlying data; a SUM grouped by customer can effectively expose an amount when that customer has only one payment. The agent need not be trying to bypass the rules. The developer therefore changed the policy so MIN and MAX require the same approval as access to individual records.

The handling of GROUP BY remains unresolved. Grouping by identifiers can reveal individuals, and seemingly ordinary fields such as email addresses or precise timestamps can also be practically unique. A minimum group size might help, but the post notes that multiple overlapping queries could still allow someone to work backwards to individual values.

In response, a community member suggests directing agents to pre-materialized, sanitized aggregate tables rather than sensitive raw data. For tighter restrictions, the commenter also points to ETL processes that clean data before queries are made. The discussion offers no definitive solution, but highlights the limits of rules based only on SQL functions. The Reddit post contains the developer’s investigation and tradeoffs: original Reddit post

🇬🇧 https://www.reddit.com/r/LLMDevs/comments/1xy0zce/i_thought_aggregates_were_safe_enough_to_let_ai

Leave a Comment

The weekly brief: selected developments, projects and videos