{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Module 9 — Compliance & Data Privacy\n",
    "\n",
    "Three things to internalize before deploying to a regulated client:\n",
    "\n",
    "1. The **ZDR eligibility matrix** — which features keep zero data retention, which don't.\n",
    "2. **HIPAA schema-caching risk** — never put PHI in tool/output schemas; their cache lifetime differs from message content.\n",
    "3. The **1.1× US-inference multiplier** — how `inference_geo: \"us\"` affects price and Priority-Tier burndown."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. ZDR matrix as a queryable dict\n",
    "\n",
    "Run this cell to look up any feature's ZDR status without re-reading the table."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ZDR = {\n",
    "    \"Adaptive Thinking\":               (True,  None),\n",
    "    \"Effort parameter\":                (True,  None),\n",
    "    \"Citations\":                       (True,  None),\n",
    "    \"Structured Outputs\":              (True,  None),\n",
    "    \"Web Search / Web Fetch (standard)\": (True, None),\n",
    "    \"Compaction\":                      (True,  None),\n",
    "    \"Bash, Computer Use, Text Editor\": (True,  None),\n",
    "    \"Message Batches API\":             (False, \"inputs/outputs stored server-side up to 29 days\"),\n",
    "    \"Files API\":                       (False, \"files stored server-side\"),\n",
    "    \"Code Execution\":                  (False, \"execution state held server-side\"),\n",
    "    \"Agent Skills\":                    (False, \"skill data follows standard retention\"),\n",
    "    \"MCP Connector\":                   (False, \"requires server-side routing\"),\n",
    "    \"Web Search + Dynamic Filtering\":  (False, \"code execution required; stores intermediate state\"),\n",
    "}\n",
    "\n",
    "for feature, (eligible, reason) in ZDR.items():\n",
    "    mark = \"YES\" if eligible else \"NO \"\n",
    "    print(f\"[{mark}] {feature}\" + (f\"  — {reason}\" if reason else \"\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. HIPAA-safe schema (generic field names)\n",
    "\n",
    "Schema property names are compiled and cached separately from message content. Real PHI values must only ever appear in message content — never in field names or descriptions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# BAD — PHI-shaped names leak through schema cache:\n",
    "bad = {\"properties\": {\"patient_id\": {\"type\": \"string\"}, \"diagnosis_code\": {\"type\": \"string\"}}}\n",
    "\n",
    "# GOOD — generic names; PHI values still flow through message content only:\n",
    "good = {\"properties\": {\"record_id\":  {\"type\": \"string\"}, \"category_code\":  {\"type\": \"string\"}}}\n",
    "\n",
    "import json\n",
    "print(\"BAD:\\n\",  json.dumps(bad, indent=2))\n",
    "print(\"GOOD:\\n\", json.dumps(good, indent=2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. Cost impact of `inference_geo: \"us\"`\n",
    "\n",
    "The 1.1× multiplier applies to **Opus 4.6 and above** (not Haiku or Sonnet below that threshold). It also affects Priority-Tier burndown — every token counts as 1.1 against committed TPM. Use the helper below to estimate the markup on a workload."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def us_inference_markup(model: str, base_cost: float) -> float:\n",
    "    \"\"\"Return the cost after applying the 1.1x US-inference multiplier where it applies.\"\"\"\n",
    "    affected = (\"claude-opus-4-6\", \"claude-opus-4-7\")  # Opus 4.6+\n",
    "    return base_cost * 1.1 if model in affected else base_cost\n",
    "\n",
    "for m in (\"claude-haiku-4-5-20251001\", \"claude-sonnet-4-6\", \"claude-opus-4-7\"):\n",
    "    print(f\"{m:<30} $100 base -> ${us_inference_markup(m, 100):.2f} with US inference\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
