Classes and objects
Set release boundaries for the ThresholdModel class
Page 7 defines what the ThresholdModel class with per-instance cutoffs must refuse before release—security here is not a pasted happy path.
1Learn the idea
Read
Threats for this artifact only
Operational risks for the ThresholdModel class with per-instance cutoffs center on storing PII inside repr or dict dumps in logs, plus the earlier failure mode (shared mutable class attribute for threshold so instances overwrite each other). Safety lives in executable gates, allowlists, redaction, and a named owner—not in a warning paragraph under an unsafe function.
Read
Run the release gate
class ThresholdModel:
def __init__(self, name, threshold, owner_email=None):
self.name=name; self.threshold=threshold; self._owner=owner_email
def __repr__(self):
return f'ThresholdModel(name={self.name!r}, threshold={self.threshold})' # no email
print(repr(ThresholdModel('Strict',0.8,'a@b.com')))
Expected evidence: repr without owner email. A failed assertion means stop, investigate, and do not publish the ThresholdModel class.
Read
Owner, retention, rollback
Name who can disable the feature, what data is retained, and how to roll back to the last known good artifact. Pin the reviewed configuration (versions, thresholds, allowlists) so “what shipped” is reconstructable for python-classes.
Read
Lab notebook: release blocker
Write the release blocker as a predicate, not a feeling: “Do not ship the ThresholdModel class if storing PII inside repr or dict dumps in logs.” Pair it with a passing control that shows the reviewed configuration still works for Strict(threshold=0.8), Loose(threshold=0.4), scores=[0.5,0.9]. Name an owner and a rollback handle (git tag, docs_version, previous image).
Security pages must not paste the happy-path demo. If your gate code looks like the implementation page, replace it with a deny/allow check aimed at storing PII inside repr or dict dumps in logs.
Read
Worked judgment
State the data retention rule in one line (what is stored, for how long, who can read it). Then state the kill switch (env flag, config pin, or feature owner). The ThresholdModel class is not shippable without both, even when assert Strict(0.8) and Loose(0.4) disagree on score 0.5 looks healthy.
Read
Why this stage matters for the ThresholdModel class
At the safety and operations stage for python-classes, the job is narrower than finishing a product demo. You are creating one progressive evidence piece about Strict(threshold=0.8), Loose(threshold=0.4), scores=(0.5,0.9) that later pages inherit without redefining success. Keep that fixture small enough to inspect by hand, keep outputs copy-pasteable as text, and refuse to narrate this baseline as if it were a production SLA: two handwritten prediction tables before coding the class.
For this page specifically, success looks like an executable deny gate for the lab-specific threat while still centering the user decision to reuse one predict method across two named models with different thresholds. If you cannot point to a file, command, or assertion that proves that for the ThresholdModel class, stay on this page instead of advancing.
Go deeper
Before you start
Why this matters
Write an attack or unsafe misuse specific to this lab: storing PII inside repr or dict dumps in logs. Predict whether your current code blocks it. Then run the gate below and compare.
In the wild
See how this idea shows up as a product and a company — then come back to the lesson. Skills transfer across vendors.
Related lessons
Check your understanding
Page assessment
Answer from memory. Completion is saved from this evidence, not from opening the next page.
All responses are required.