← sources

My agent figured out how to read sensitive data through “harmless” aggregate queries

source: reddit (reddit:AI_Agents)published 2026-11-16 20:47ingested 2026-11-17 02:35

retained text

I’ve been working on access rules for agents that query a Postgres database. Some fields are sensitive, like payment amounts, so if the agent wants to read those rows directly a person has to approve it first. Aggregates were allowed without approval, because the agent asking for total refunds this quarter seemed fine. That way it can still do useful analytics without seeing anyone’s actual payments.

Then I watched what queries the agent actually wrote, and the rule didn’t hold up.

It didn’t need to read the rows. MAX(amount) isn’t a summary, it’s one real payment from one row. Same with MIN. And SUM(amount) GROUP BY customer\_id gives one total per customer, which is basically reading the sensitive column customer by customer. All of these went through as aggregates and skipped the approval. The agent wasn’t being sneaky, those are just normal queries for the questions it was asked, which is kind of the point.

The rule was checking what kind of function the query used, not how many rows were behind each value it returned. An aggregate over a million rows and an aggregate over one row looked exactly the same.

MIN and MAX were easy, they now count as row reads so they need the same approval. Grouping I haven’t settled. One option is treating GROUP BY on identifier columns as row access, but near-unique columns like emails or timestamps slip through. The other is a minimum group size, k-anonymity style, which catches more but changes the results, and an agent running a few overlapping queries could still narrow things down. Agents are pretty good at running a few overlapping queries.

Full investigation in a comment. 

document fetched 2026-11-17 00:18 · canonical https://reddit.com/r/AI_Agents/comments/1xy0rxa/my_agent_figured_out_how_to_read_sensitive_data