Alex Chen

Expected transformation:

input keys:  date, steps, sleep_minutes, medication, note
purpose:     activity_summary
output keys: date, steps

Enter fullscreen mode Exit fullscreen mode

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, not results from this lesson.

Prerequisite and tiny program

Use Python 3.11 or newer and only the standard library. The following code and outputs are labeled unexecuted examples.

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}

Enter fullscreen mode Exit fullscreen mode

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.

Tests express the privacy rule

Place this beside the function in test_minimize.py, adjusting the import name to your file:

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()

Enter fullscreen mode Exit fullscreen mode

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.

Try the bad input first

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.

What this teaches—and what it does not

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.