Learn Data Minimization With a Tiny Python Health-Record Filter A developer demonstrates data minimization with a tiny Python health-record filter that passes only the fields a declared purpose needs, using a policy map and fail-closed behavior. The exercise is timely because OpenAI announced Health in ChatGPT on July 23, 2026, which connects medical records and Apple Health for eligible US users, stating that connected data is not used to train foundation models or target ads. Expected transformation: input keys: date, steps, sleep minutes, medication, note purpose: activity summary output keys: date, steps The learning question is not “how do I analyze health data?” It is “how can a program prove that one purpose receives fewer fields than the original record?” That is data minimization: collecting or passing only what a declared task needs. This exercise is timely because OpenAI announced Health in ChatGPT on July 23, 2026. OpenAI says the rollout covers eligible US users who are logged in, age 18+, and using web or iOS. It says supported connections include medical records and Apple Health, and a dashboard may cover labs, medications, activity, sleep, and other health information. OpenAI further states connected data and relevant conversations are not used to train foundation models or target ads. Those are company statements from the primary source https://openai.com/index/health-in-chatgpt/ , not results from this lesson. Use Python 3.11 or newer and only the standard library. The following code and outputs are labeled unexecuted examples . python from copy import deepcopy POLICY = { "activity summary": {"date", "steps"}, "sleep summary": {"date", "sleep minutes"}, } def minimize record: dict, purpose: str - dict: if purpose not in POLICY: raise ValueError f"unknown purpose: {purpose}" allowed = POLICY purpose return {key: deepcopy value for key, value in record.items if key in allowed} There are two important choices. The policy maps purposes to fields instead of maintaining one giant “safe” list. Also, an unknown purpose raises an error rather than returning the complete input. That second behavior is fail-closed. Place this beside the function in test minimize.py , adjusting the import name to your file: python import unittest from minimizer import minimize RECORD = { "date": "2026-07-20", "steps": 4200, "sleep minutes": 395, "medication": "example-only" , "note": "private free text", } class MinimizerTests unittest.TestCase : def test activity keeps exact fields self : out = minimize RECORD, "activity summary" self.assertEqual out, {"date": "2026-07-20", "steps": 4200} def test input is not changed self : before = RECORD.copy minimize RECORD, "sleep summary" self.assertEqual RECORD, before def test unknown purpose fails closed self : with self.assertRaises ValueError : minimize RECORD, "personalization" if name == " main ": unittest.main The intended command is python3 -m unittest -v . Because it was not run for this article, readers should treat the expected three successful tests as a target, not observed evidence. Add "location history": ... to RECORD . The activity test should still expect exactly two output fields. If a future edit changes the implementation to return all fields, that equality assertion fails visibly. Next, add a policy typo such as activity summry ; the unknown-purpose test explains why silently guessing would be risky. Common mistakes include deleting keys from the original dictionary, using record.get for an unknown policy, and testing only that steps exists rather than checking the whole output. A minimizer test should detect extra information, not merely missing information. After the exercise, a learner should be able to explain purpose limitation, field allowlists, fail-closed behavior, and negative tests. An extension is to represent each policy with an owner and expiry date, then reject expired policies. This toy handles flat dictionaries only. It does not sanitize values, understand nested clinical formats, anonymize people, validate accuracy, secure files, enforce deletion, or integrate with any announced service. The sample values are fictional and provide no medical meaning. Never use the function as a production health-data control without a broader privacy and security review. OpenAI says its health feature is designed to support rather than replace medical care and is not intended for diagnosis or treatment. This programming lesson likewise offers no medical advice and makes no clinical claim. AI assistance disclosure: This article was drafted with AI assistance and reviewed against the cited primary source.