{"slug": "learn-data-minimization-with-a-tiny-python-health-record-filter", "title": "Learn Data Minimization With a Tiny Python Health-Record Filter", "summary": "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.", "body_md": "Expected transformation:\n\n```\ninput keys:  date, steps, sleep_minutes, medication, note\npurpose:     activity_summary\noutput keys: date, steps\n```\n\nThe 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.\n\nThis 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.\n\nUse Python 3.11 or newer and only the standard library. The following code and outputs are labeled **unexecuted examples**.\n\n``` python\nfrom copy import deepcopy\n\nPOLICY = {\n    \"activity_summary\": {\"date\", \"steps\"},\n    \"sleep_summary\": {\"date\", \"sleep_minutes\"},\n}\n\ndef minimize(record: dict, purpose: str) -> dict:\n    if purpose not in POLICY:\n        raise ValueError(f\"unknown purpose: {purpose}\")\n    allowed = POLICY[purpose]\n    return {key: deepcopy(value) for key, value in record.items()\n            if key in allowed}\n```\n\nThere 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.\n\nPlace this beside the function in `test_minimize.py`\n\n, adjusting the import name to your file:\n\n``` python\nimport unittest\nfrom minimizer import minimize\n\nRECORD = {\n    \"date\": \"2026-07-20\",\n    \"steps\": 4200,\n    \"sleep_minutes\": 395,\n    \"medication\": [\"example-only\"],\n    \"note\": \"private free text\",\n}\n\nclass MinimizerTests(unittest.TestCase):\n    def test_activity_keeps_exact_fields(self):\n        out = minimize(RECORD, \"activity_summary\")\n        self.assertEqual(out, {\"date\": \"2026-07-20\", \"steps\": 4200})\n\n    def test_input_is_not_changed(self):\n        before = RECORD.copy()\n        minimize(RECORD, \"sleep_summary\")\n        self.assertEqual(RECORD, before)\n\n    def test_unknown_purpose_fails_closed(self):\n        with self.assertRaises(ValueError):\n            minimize(RECORD, \"personalization\")\n\nif __name__ == \"__main__\":\n    unittest.main()\n```\n\nThe intended command is `python3 -m unittest -v`\n\n. Because it was not run for this article, readers should treat the expected three successful tests as a target, not observed evidence.\n\nAdd `\"location_history\": [...]`\n\nto `RECORD`\n\n. 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`\n\n; the unknown-purpose test explains why silently guessing would be risky.\n\nCommon mistakes include deleting keys from the original dictionary, using `record.get()`\n\nfor an unknown policy, and testing only that `steps`\n\nexists rather than checking the whole output. A minimizer test should detect extra information, not merely missing information.\n\nAfter 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.\n\nThis 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.\n\nOpenAI 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.\n\nAI assistance disclosure: This article was drafted with AI assistance and reviewed against the cited primary source.", "url": "https://wpnews.pro/news/learn-data-minimization-with-a-tiny-python-health-record-filter", "canonical_source": "https://dev.to/magickong/learn-data-minimization-with-a-tiny-python-health-record-filter-9de", "published_at": "2026-07-25 11:02:55+00:00", "updated_at": "2026-07-25 11:32:45.517868+00:00", "lang": "en", "topics": ["developer-tools", "ai-products"], "entities": ["OpenAI", "ChatGPT", "Apple Health"], "alternates": {"html": "https://wpnews.pro/news/learn-data-minimization-with-a-tiny-python-health-record-filter", "markdown": "https://wpnews.pro/news/learn-data-minimization-with-a-tiny-python-health-record-filter.md", "text": "https://wpnews.pro/news/learn-data-minimization-with-a-tiny-python-health-record-filter.txt", "jsonld": "https://wpnews.pro/news/learn-data-minimization-with-a-tiny-python-health-record-filter.jsonld"}}