Topic 5 of 5 · 4 min read
Data exposure in hosted notebook agents
Goal: Decide which data a hosted notebook agent may see for a task and prepare a safe sample when the full table is off limits.
Treat anything a hosted notebook agent can read as data you are sending to a third party, and decide what it may see before you open the chat. Often the model needs only the schema, not the rows.
Check yourself · 1 of 3
Which input is usually enough for a hosted agent to write a correct groupby for your table?
Why it matters
A notebook assistant builds a prompt from your question and from context: the cell, nearby cells, variable names, and sometimes dataframe previews or cell outputs. In hosted tools that prompt goes to a model provider. A cell that printed df.head() with customer names and emails has just put them in the context. Client contracts, privacy law and your employer's policy may not allow that, regardless of how useful the answer is.
Tools differ. Some can run against a model you host yourself, some send context only on request, and some include outputs by default. Read your tool's data-handling settings and your organisation's policy; do not guess.
How to do it
- Classify the data. Public, internal, personal (names, emails, phone numbers, ids that identify a person), client-confidential, regulated (health, payment). Higher classes need a stricter route.
- Decide what the task needs. Writing a groupby needs column names and types. Debugging a parse error needs a few lines of the bad field. Few tasks need real personal values.
- Share the least that works:
- Schema only: column names, types, and a note such as "amount in cents."
- Synthetic rows: invented values with the same shape, for example
user_8841, a***@example.com. - Masked sample: real structure, with identifiers replaced by hashes or tokens, and free text removed.
- Control outputs. Avoid cells that print raw rows while an agent is attached. Clear sensitive outputs before sharing the notebook.
- Keep secrets out. Connection strings and keys go in environment variables or a secret store, never in a cell.
- Run code where the data lives. Let the agent write the code from a schema, then run it yourself against the full table in your own environment.
Before and after
Before: "Here is my customers table, find why signup dates are wrong," followed by pasting 200 real rows.
After: "Table customers(id text, email text, signup_ts text). Example rows: ('c_001', 'x@example.com', '03/11/2026 14:02'), ('c_002', 'y@example.com', '2026-11-03T14:02:00Z'). Mixed date formats. Write a parser that handles both." The agent has what it needs and no real person's data.
What goes wrong
- Outputs in context. A previewed dataframe is sent along with the next question.
- "Anonymised" rows that identify people. A rare job title plus a postcode can point to one person.
- Shared notebooks. Saved outputs still contain the rows.
- Free-text columns. Notes and comments often hold names and phone numbers that a column filter misses.
Examples
A safe sample for a parsing bug
The real column has client names in a notes field. Build the sample with the structure intact and the content replaced:
sample = df.head(5).copy()
sample['client_id'] = ['c_' + str(i) for i in range(len(sample))]
sample['notes'] = 'redacted'
Share sample and the error message. Run the fixed code on the full table yourself.
A rule a team could adopt
Personal and client data stay out of hosted notebook agents. Agents may see schemas, synthetic rows and masked samples. Anything printed in a cell while an agent is attached counts as shared. Secrets never appear in cells. Exceptions need approval from the data owner.
Key points
- Anything a hosted agent can read, including cell outputs and previews, may be sent to a model provider.
- Classify the data first, and let the class set the route: hosted, self-hosted or no AI.
- Most coding tasks need only the schema or a few synthetic rows, not real values.
- Mask or tokenise identifiers and drop free-text columns before sharing a sample.
- Keep secrets in environment variables and clear sensitive outputs before sharing a notebook.
Common mistakes
- Calling df.head() on real personal data while an assistant is attached to the notebook.
- Assuming a masked sample is safe without checking free-text columns and rare combinations.
- Putting credentials in a cell because the agent needed them to run the query.
- Sharing a notebook with saved outputs that still show real rows.
Check yourself · 2 of 3
You printed df.head() containing customer emails while an assistant panel was attached. What is the safest assumption?
Check yourself · 3 of 3
A free-text notes column in a client table may contain names and phone numbers. How should it appear in a sample for an agent?
Practice items, not counted towards your mastery.
Start here
- Jupyter AI documentation (opens in a new tab)DocsFree
How the chat and magic-command assistants work in JupyterLab, and how to point them at different model providers.
- marimo reactive Python notebooks (opens in a new tab)ToolFree
A notebook that stores plain .py files and re-runs dependent cells, which removes hidden state by design.
- Ten simple rules for reproducible research in Jupyter notebooks (opens in a new tab)PaperFree
Concrete rules for ordering cells, recording dependencies and sharing notebooks that others can re-run.