Skip to main content

How do I log LLM prompts and student responses for a study without storing PII?

Send every model call through your own server. Replace student identifiers with a keyed pseudonym, strip names and contact details from free text before the prompt goes to the provider, and keep the identity key away from the log. For a pilot-scale platform, building and testing this usually takes 40–80 hours of engineering.

Where PII gets into an LLM study log

PII gets in at three points, and each one needs its own control. The first is the identifiers on each log row: student ID, email, the roster name the app shows on screen. The second is free text. Students type their names, their teachers’ names, their school and sometimes their home situation into chat boxes.

The third is the model provider. Once a prompt leaves your system, it falls under the provider’s retention terms, not yours. Redaction has to happen before the API call, not after the response comes back.

This page covers capture: how the study records data while it runs. Preparing a finished dataset for sharing or deposit is a separate step with its own rules. A clean capture design makes that later step much smaller.

A logging schema for prompt and response events

Log one row per model call, in an events table that never contains a real identifier. These fields cover what an efficacy analysis usually needs.

Field Example Why it is there
event_id UUID A unique key for each call
study_pid p_7f3a91c2 The keyed pseudonym, never the district ID
session_id UUID Groups turns into one sitting
condition_arm B_socratic Which prompting strategy or model the student was assigned
prompt_template_id / version hint_v3 Ties each output to the exact template that produced it
model / params model name, temperature Lets you reproduce results after the provider updates a model
student_input_redacted "My name is [STUDENT]…" What the student typed, after redaction
response_text model output What the student actually saw
redaction_flags {name:1, email:0} Counts of what was removed, for auditing
ts_utc, latency_ms, tokens timestamps and counts For timing analysis and cost tracking

Store the template text and the condition assignments in separate versioned tables, not as copies on every row. Store the final prompt as it was sent, after redaction. That is the only version that should exist anywhere.

Worked example: the volume

Take a pilot with 500 students, 30 sessions each and about 8 turns per session: that is 120,000 rows. At roughly 4 KB per row, the raw log comes to about 500 MB. That is small enough for a Postgres or Firestore instance with row-level access rules, so it does not need a data warehouse.

Redaction before the data reaches the model provider

The browser should never call the model API directly. Put a server-side proxy in front of the API and have it run these passes, in this order, on every request:

  1. Swap the app’s identifiers for the pseudonym. The prompt template only ever gets study_pid and generic labels such as "the student".
  2. Run pattern redaction for emails, phone numbers, URLs, street addresses and the district’s student ID format.
  3. Run roster matching. The server holds the class roster and replaces any first or last name that appears with [STUDENT] or [TEACHER]. The roster itself never goes to the provider.
  4. Optionally, run a named-entity model to catch names that are not on the roster, such as siblings or school names.
  5. Record what each pass removed in redaction_flags, then send the request.

Redaction is never perfect. Before the pilot starts, run the pipeline on a set of at least 200 sample student responses, have a person review the output, and write down the miss rate. Your IRB and the district will want that number, and it is more credible than saying the pipeline "removes PII".

Designing the pseudonymous ID

  • Use a keyed hash such as HMAC-SHA256(study_key, district_student_id), not a plain SHA-256 hash. Student ID numbers are short, so plain hashes can be reversed by brute force in minutes.
  • Keep study_key in a secrets manager such as AWS Secrets Manager or Google Secret Manager. Never put it in the repository or the database.
  • Use a different key for each study, so the same child’s records cannot be linked across studies by accident.
  • If anyone needs to re-identify students, for example to join assessment scores, keep the linking table with the PI or the district, in a separate store with separate access.

When the study ends and the key is destroyed according to the protocol, the pseudonyms can no longer be reversed. Whether that counts as de-identified under FERPA is a determination for your institution’s counsel and compliance office, not for the engineering team.

Retention settings and what to confirm with the provider

Your own system’s retention should follow the data use agreement and the IRB protocol. A common pattern:

Data Typical retention Access
Events log (redacted) Study period plus the analysis window in the protocol Research team
Redaction review queue 30 days, then purged Two named reviewers
Linking table Until the protocol’s destruction date PI or district only
Application and error logs 14–30 days, with request bodies excluded Engineering

Application logs are the usual leak. Make sure the proxy does not write request bodies to CloudWatch, Firebase logs or an error tracker.

Questions to settle in writing with the model provider

  • Whether API inputs and outputs are used for training, and whether that is in the contract or only in a policy page.
  • How long requests are kept for abuse monitoring. Many providers default to up to 30 days.
  • Whether zero data retention is available, whether it needs a separate approval or agreement, and whether your account has it turned on.
  • Which features are not covered by zero retention. Stored conversations, file uploads, batch jobs and fine-tuning often require storage.
  • Whether the agreement is under the institution’s account or a personal card, and which region and subprocessors handle the data.

Keep the signed terms and a screenshot of the account setting in the study’s compliance file. Districts doing an IT review increasingly ask for both.

Who signs off, and where we fit

The engineering team builds the controls and documents them. The IRB approves the protocol. Your institution’s counsel or compliance office decides whether the design meets FERPA, and COPPA too if the platform serves children under 13 directly. The district decides whether the design fits its data privacy agreement.

We have built this kind of pipeline under deadline. One example: we took a research prototype to a district-approved classroom pilot in under 30 days, with 20 teachers across two districts. The data handling was documented well enough to get through both districts’ reviews.

Frequently asked questions

Can I just hash student IDs before logging them?
Not with a plain hash. Student ID numbers come from a small range, so anyone who has the log can hash every possible ID and match them. Use a keyed hash such as HMAC-SHA256, with a key for each study stored in a secrets manager.

Does zero data retention mean the model provider stores nothing?
It usually means requests are not kept after processing. Some features, such as stored conversations, file uploads or batch jobs, may be excluded. Get the scope in writing, check which endpoints and features it covers, and confirm the setting is turned on for your account.

Is redacting free text enough to make the log FERPA compliant?
Redaction lowers the risk, but compliance depends on the whole design: the agreements, access controls, retention and what the data could be linked to. Your institution’s counsel or compliance office makes that call. The engineering team’s job is to document the controls and the measured redaction miss rate.

How long does it take to build a PII-safe logging pipeline?
For a pilot-scale platform, plan on 40–80 engineering hours. That covers the proxy, the redaction passes, pseudonymous IDs, the schema, retention jobs and a validation run on sample responses. The top of the range is for platforms with several model providers or voice input.

How is this different from de-identifying data for sharing?
This page covers capture: keeping PII out of the log and away from the model provider while the study runs. De-identifying for sharing happens after the study and prepares a dataset for publication or deposit. Good capture design makes the sharing step much smaller.

Related answers

Planning a pilot that logs LLM interactions?

We offer a free 30-minute review of your pilot plan or the technical section of your proposal. Bring the prototype’s repository or a demo, the pilot timeline, and the requirements from your funder and IRB. Start a conversation.