Skip to content
Datablare
Security

Hide Sensitive Columns from AI: Column-Level Security

Column level security for AI agents: how to hide sensitive columns from Claude or ChatGPT over MCP, the SQL tricks that leak them, and how to block them.

Published 6 min read
On this page
  1. What column-level security means
  2. Why AI agents make column controls more important
  3. The SQL that defeats naive column filters
  4. Doing it properly: parse, resolve, fail closed
  5. Column controls versus the alternatives
  6. Which columns to hide
  7. Limits worth being honest about
  8. How Datablare hides columns

To hide sensitive columns from AI, you need column-level security that holds whatever SQL the agent writes. In practice that means two layers. First, give the AI’s database login column-level grants that leave out fields such as phone, email, Aadhaar, PAN, salary or diagnosis. Second, put a gateway between the AI and the database that drops those columns from the schema the agent sees, and refuses any query that reads them, including through SELECT *, aliases and subqueries. This post explains why simple filters fail and how to set up both layers.

What column-level security means

Column-level security restricts which fields a user can read, even when they can read the table. A support analyst might read orders but not orders.customer_phone. It’s the column counterpart of row-level security, which restricts which records a user can read.

Databases have supported column controls for a long time. PostgreSQL, MySQL, MariaDB, SQL Server and ClickHouse let you grant SELECT on specific columns. On Oracle and Snowflake, views and masking policies usually do the same job. What’s new is the reader. An AI agent connected through the Model Context Protocol (MCP) writes its own SQL, and you can’t review it before it runs.

Why AI agents make column controls more important

When a person runs a report, they choose the columns. When an AI agent answers a question, the model chooses, and the rows it reads become part of its context. Three consequences:

  1. Whatever the agent reads, the AI provider receives. Query results go to Claude, ChatGPT or whichever model you use, under that provider’s terms. Hiding a column is how you keep that field away from every AI provider.
  2. Agents over-select. Models often start with SELECT * ... LIMIT 10 to explore a table. Without column controls, that one query pulls every field.
  3. Agents are persistent. If a query is refused, the agent tries another form. Your control has to hold against rephrasing, not just the first attempt.

The SQL that defeats naive column filters

A common first attempt is a text filter: refuse any query containing the word phone. It fails quickly.

Query patternWhy a text filter misses it
SELECT * FROM customersThe column is never named
SELECT c.* FROM customers cSame, through an alias
SELECT phone AS contact FROM customersCaught by name, but "PHONE" or a quoted identifier may not be
WITH x AS (SELECT * FROM customers) SELECT * FROM xThe column flows through a CTE
SELECT row_to_json(c) FROM customers cA whole-row reference in PostgreSQL, no column named
SELECT id FROM customers WHERE phone LIKE '98%'The column isn’t returned, but it’s read and filtered on
SELECT name FROM customers JOIN leads USING (id)Ambiguous names across joined tables

The WHERE case is easy to overlook. A query that only returns ids can still reveal a hidden value if it filters on it: run enough LIKE prefixes and you can reconstruct a phone number. A real column guard treats reading a column anywhere in the query, not only in the SELECT list, as reading it.

Doing it properly: parse, resolve, fail closed

A column guard that holds up needs to:

  • Parse the SQL with a real parser for the database’s dialect, not regular expressions.
  • Expand SELECT * against the actual columns of the table, read from the database.
  • Resolve every column reference to the physical table it comes from, through aliases, CTEs, subqueries and functions.
  • Refuse whole-row references on tables with hidden columns.
  • Fail closed. If a column can’t be resolved, because it’s ambiguous or unknown, refuse. “Could not tell” isn’t the same as “not hidden”.
  • Check the result too. Parsers aren’t perfect, so check the returned column names after the query runs, and drop the result if a hidden column appears.
  • Leave hidden columns out of the schema the agent sees. An agent that never learns aadhaar_number exists has no reason to ask for it.

And keep the database layer underneath. A column-level grant on the AI’s read-only login is a control you hold yourself, enforced by the database independently of any gateway.

Column controls versus the alternatives

ApproachStrengthWeakness
Column-level GRANT on the AI’s loginEnforced by the database itselfPer-login; changes need a DBA; the agent may still try and fail without explanation
Database view without the columnSimple; can also filter rows and roll up dataOne more object to maintain per use case
Masking or tokenising the columnKeeps the column usable for joinsSetup varies by engine; masked values can still be identifying
Gateway column hiding (MCP)Per project; immediate; schema and refusals visible in an audit logDepends on SQL parsing, so pair it with a grant
Prompt instruction (“don’t read phone”)NoneA request, not a control

Most teams end up with a grant or view at the database, plus gateway hiding for day-to-day control and visibility.

Which columns to hide

Start with anything that identifies or harms a person if exposed:

  • Contact: phone, email, full address
  • Government IDs: Aadhaar, PAN, passport, voter ID, GSTIN of individuals
  • Financial: salary, bank account, UPI id, card fragments, credit scores
  • Health: diagnosis, prescriptions, test results
  • Credentials: password hashes, API keys, session tokens stored in tables
  • Free text: notes, comments, support messages. They often contain all of the above.

Then ask what the agent actually needs. “Revenue by city” needs city, not address. “Repeat purchase rate” needs a customer id, not a name.

Limits worth being honest about

  • Column controls are not row-level security. If a regional manager should only see their region, use a filtered view or the database’s row-level policies.
  • Inference is possible. An aggregate over a group of one reveals an individual. Pincode plus date of birth plus gender can identify people. Hide or roll up quasi-identifiers where it matters.
  • Context leaks. Don’t describe hidden columns in table descriptions or agent rules. The agent reads those.
  • Visible columns are fully visible. Whatever you leave exposed, the agent and its AI provider can read.

How Datablare hides columns

In Datablare, a project manager controls what agents can read at three levels:

  1. Which tables are exposed: in the data connection settings. Tables you don’t select don’t exist as far as agents are concerned.
  2. Agent access per table: in Modeling. A table can stay documented but refuse every query.
  3. Hidden columns: in Modeling → table → Columns, switch a column off. It takes effect at once.

When a column is hidden, Datablare:

  • Leaves it out of the tables and columns the agent is told about, along with relationships that touch it. The in-app “What Claude sees” preview shows exactly that answer.
  • Parses each query with a dialect-aware SQL parser, expands SELECT *, follows aliases, CTEs and subqueries back to the source table, and refuses the query if a hidden column is read anywhere, including in a WHERE.
  • Refuses whole-row references on that table, and refuses columns it can’t resolve.
  • Checks the result’s column names after the query runs, and withholds the result if a hidden column slipped through.
  • Records each refusal in Audit as Hidden column, and records who hid or unhid a column in Audit → Changes.

All of this sits on top of read-only enforcement: an SQL guard that allows only a plain read, and a read-only database session, or on SQL Server and Snowflake a transaction that is always rolled back. When you add a source, Datablare shows the SQL to create a read-only login for your engine, including how to keep a single column out at the database too.

It works the same across the seven supported engines: PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, ClickHouse and Snowflake. Read more on how it works and the security page, or create a free account and try hiding a column on the sample e-commerce data.

Frequently asked questions

How do I hide columns from AI tools like Claude or ChatGPT?

Use two layers. At the database, give the AI's read-only login column-level grants that leave sensitive columns out. In the gateway between the AI and the database, hide the columns so they are left out of the schema the agent sees and any query that reads them is refused.

Does SELECT * expose hidden columns?

It can. A naive filter that looks for column names in the SQL text misses SELECT *, aliases and whole-row references. A proper column guard expands SELECT * against the real table, traces aliases back to their source and refuses the query if any hidden column would be read.

Is hiding a column the same as row-level security?

No. Column-level security controls which fields can be read; row-level security controls which records. If people should only see their own region's orders, use a filtered view or your database's row-level policies alongside column controls.

Can an AI still infer hidden data?

Sometimes. Aggregates over very small groups, free-text columns that contain personal details, and other columns that identify people can all reveal more than intended. Hide those too, or expose a view that rolls data up to safer levels.

Keep reading

Give your team answers, not database logins.

Start free with the e-commerce sample or your own database. Connect Claude in about two minutes.

30 minutes with the founder. Or WhatsApp / [email protected]