WorldSociety

Learn Data Minimization With a Tiny Python Health-Record Filter

Expected transformation:input keys: date, steps, sleep_minutes, medication, note purpose: activity_summary output keys: date, stepsEnter fullscreen modeExit fullscreen modeThe learning question is not “how do. . .

· 3 min read

Learn Data Minimization With a Tiny Python Health-Record Filter

Expected transformation:input keys: date, steps, sleep_minutes, medication, note purpose: activity_summary output keys: date, stepsEnter fullscreen modeExit fullscreen modeThe 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 fromthe primary source, not results from this lesson. Prerequisite and tiny programUse Python 3. 11 or newer and only the standard library. The following code and outputs are labeledunexecuted examples. fromcopyimportdeepcopyPOLICY={"activity_summary":{"date","steps"},"sleep_summary":{"date","sleep_minutes"},}defminimize(record:dict,purpose:str)->dict:ifpurposenotinPOLICY:raiseValueError(f"unknown purpose:{purpose}")allowed=POLICY[purpose]return{key:deepcopy(value)forkey,valueinrecord. items()ifkeyinallowed}Enter fullscreen modeExit fullscreen modeThere 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. Tests express the privacy rulePlace this beside the function intest_minimize. py, adjusting the import name to your file:importunittestfromminimizerimportminimizeRECORD={"date":"2026-07-20","steps":4200,"sleep_minutes":395,"medication":["example-only"],"note":"private free text",}classMinimizerTests(unittest. TestCase):deftest_activity_keeps_exact_fields(self):out=minimize(RECORD,"activity_summary")self. assertEqual(out,{"date":"2026-07-20","steps":4200})deftest_input_is_not_changed(self):before=RECORD. copy()minimize(RECORD,"sleep_summary")self. assertEqual(RECORD,before)deftest_unknown_purpose_fails_closed(self):withself. assertRaises(ValueError):minimize(RECORD,"personalization")if__name__=="__main__":unittest. main()Enter fullscreen modeExit fullscreen modeThe intended command ispython3 -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. Try the bad input firstAdd"location_history": [. . . ]toRECORD. 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 asactivity_summry; the unknown-purpose test explains why silently guessing would be risky. Common mistakes include deleting keys from the original dictionary, usingrecord. get()for an unknown policy, and testing only thatstepsexists rather than checking the whole output. A minimizer test should detect extra information, not merely missing information. What this teaches—and what it does notAfter 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.

Source: dev.to

More Health news