The requirement comes first: if an AI coding agent in Cursor can query a database, every sensitive field in the result has to be redacted before the agent sees it. Data masking that runs anywhere downstream of the agent is already too late, because the raw value has crossed into a process you do not control and may forward to a model.
So masking cannot be a setting inside Cursor. It has to live on the connection, between the database and the agent, applied to results in flight. Where exactly the redaction happens turns out to be the whole question, and most setups get the placement wrong.
Why data masking belongs on the connection
An agent debugging a checkout bug runs SELECT * FROM users WHERE id = 4412. The row comes back with an email, a hashed-but-reversible token, and a billing address. The agent did not ask for PII. The query just returned it, and now it sits in the agent's context and possibly in a prompt to the model.
You cannot fix this by trusting the agent to ignore the columns. An agent that improvises will sometimes echo a value back into a comment, a test fixture, or a log line. The only reliable point of control is the path the data travels. Redact at the boundary, and the agent never receives the raw value in the first place, so there is nothing for it to mishandle.
Masking that lives in the application or in a post-processing step assumes the data already arrived safely. By then the exposure has happened. The boundary that matters is the one between the database and the agent, and it is the only place where redaction actually prevents the leak rather than documenting it.
How data masking works through hoop.dev
hoop.dev is an open-source Layer 7 access gateway. The agent reaches Postgres or MySQL through it, and on the return path the masking plugin inspects results at the protocol layer and redacts sensitive fields before they leave the gateway.
- Masking runs on the streaming result, so the email becomes
[redacted] before it reaches the agent. - Classification uses a configured DLP provider such as Presidio, not a brittle hand-written regex that misses a format.
- The same session is recorded at the gateway, so you can see what query ran and confirm the result was masked.
hoop.dev governs the data the agent receives over the connection. It does not read the model's prompt or output; it acts on query results, which is exactly where the PII leak happens. That distinction matters: the value of masking comes from intercepting data, not from watching the agent think. The wider gateway model is described on the hoop.dev site.
Setting it up
- Run the hoop.dev agent next to your database and register it as a connection.
- Configure a DLP provider so the gateway can classify fields like email, phone, and card numbers.
- Enable masking on the connection the Cursor agent uses.
- Run a test query and confirm the sensitive columns return redacted while the rest of the row is intact.
One end exposes raw rows to whatever queries them. The other redacts before the row leaves the boundary. Masking on the connection is the second.
Pitfalls to avoid
Do not assume masking is on for every connection by default. Support is per connection: native on databases like Postgres and MySQL, configured per case on others, and absent on protocols like SSH and RDP. Check the connection you are actually using. And do not point the agent at an unmasked replica thinking the data is harmless; a replica of production PII is still production PII.
FAQ
Does data masking change the data in the database?
No. Masking applies to results in flight. The stored data is untouched; the agent simply receives a redacted view.
Can the agent bypass masking?
Not when it connects through the gateway. The redaction happens on the connection before results return, outside the agent's reach.
Does hoop.dev see the model prompt?
No. It masks query results on the database connection. It does not inspect the prompt, completion, or reasoning.
Put masking where it belongs, on the connection. Read how the masking plugin works in the hoop.dev GitHub repository and configure a DLP provider with the getting started guide.