scripts/verify_iip0044_foundry_v1_3_biologics.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0044_foundry_v1_3_biologics.py · SHA-256: 1d6c53a0817f6254…
sec_top_qc_bad = True
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: sec_mals_dls.{gen_k} must be a strict boolean",
)
elif sec[gen_k] is False:
sec_top_qc_bad = True
# R16 Shared Blocker #1 + 0039-M2: Mandatory per-mixture physical co-formulation SEC-MALS/DLS binding!
# Every measured physical 1:1 co-formulation mixture MUST be explicitly registered with a unique
# mixture_id, exact (comp1_expression_batch_id, comp2_expression_batch_id) lot pair, and its own
# per-mixture monomer_pct (>= 95.0%), dls_pdi (<= 0.15), no_aggregates_or_precipitation=True, and qc_passed,
# plus optional strictly validated laboratory 1:1 molar-ratio attestation fields (equimolar_1to1_molar_ratio_attested,
# ratio_basis_attestation) documenting that 1:1 stoichiometry is laboratory-attested alongside SEC-MALS/DLS QC.
_required_mix_keys = frozenset({
"mixture_id",
"comp1_expression_batch_id",
"comp2_expression_batch_id",
"monomer_pct",
"dls_pdi",
"no_aggregates_or_precipitation",
"qc_passed",
})
_optional_mix_keys = frozenset({
"equimolar_1to1_molar_ratio_attested",
"ratio_basis_attestation",
})
_allowed_mix_keys = _required_mix_keys | _optional_mix_keys
_allowed_mix_ratio_basis_tokens = frozenset({
"LAB_ATTESTED_1TO1_MOLAR_COFORMULATION_MIXING_PROTOCOL",
"UV_A280_EXTINCTION_VERIFIED_1TO1_MOLAR_COFORMULATION",
})
raw_mixtures = sec.get("qualified_coformulation_mixtures")
candidate_passing_mixtures: dict[str, tuple[str, str]] = {}
candidate_mixture_ratio_meta: dict[str, dict[str, Any]] = {}
valid_mix_monomers: list[float] = []
valid_mix_pdis: list[float] = []
top_sec_overstated = False
if not isinstance(raw_mixtures, list) or len(raw_mixtures) == 0:
sec_input_missing_or_malformed = True
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: sec_mals_dls_monomer_coformulation missing "
"mandatory non-empty qualified_coformulation_mixtures list binding each physical 1:1 mixture_id "
"to its exact (comp1_expression_batch_id, comp2_expression_batch_id) pair and per-mixture monomer/PDI QC",
)
else:
mix_id_counts: dict[str, int] = {}
for m_rec in raw_mixtures:
if isinstance(m_rec, dict):
raw_mid = m_rec.get("mixture_id")
if type(raw_mid) is str and raw_mid.strip():
mix_id_counts[raw_mid.strip()] = mix_id_counts.get(raw_mid.strip(), 0) + 1
conflicted_mixture_ids = {k for k, cnt in mix_id_counts.items() if cnt > 1}
for cmid in sorted(conflicted_mixture_ids):
sec_input_missing_or_malformed = True
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: Duplicate/conflicting sec_mals_dls "
f"qualified_coformulation_mixtures mixture_id={cmid!r} (count={mix_id_counts[cmid]}); "
f"all occurrences excluded from physical co-formulation qualification",
)
for m_idx, m_rec in enumerate(raw_mixtures):
mlbl = f"sec_mals_dls.qualified_coformulation_mixtures[{m_idx}]"
if not isinstance(m_rec, dict):
sec_input_missing_or_malformed = True
_escalate("HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {mlbl} must be an object")
continue
extra_mk = sorted(set(m_rec.keys()) - _allowed_mix_keys)
missing_mk = sorted(_required_mix_keys - set(m_rec.keys()))
mix_ok = True
if extra_mk or missing_mk:
mix_ok = False
sec_input_missing_or_malformed = True
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {mlbl} closed-schema key violation "
f"(missing={missing_mk}, extra={extra_mk})",
)
raw_mid = m_rec.get("mixture_id")
mid_s: str | None = None
if (
type(raw_mid) is not str
or not raw_mid
or raw_mid != raw_mid.strip()
or not _SHIELD_STRICT_ID_RE.match(raw_mid)
):
mix_ok = False
sec_input_missing_or_malformed = True
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {mlbl}.mixture_id must be a non-empty "
f"unpadded ID matching {_SHIELD_STRICT_ID_RE.pattern} (got {raw_mid!r})",
)
elif raw_mid in conflicted_mixture_ids:
mix_ok = False
else:
mid_s = raw_mid
c1_bid = m_rec.get("comp1_expression_batch_id")
if (
type(c1_bid) is not str
or not c1_bid
or c1_bid != c1_bid.strip()
or c1_bid not in passing_batch_constructs
or _SHIELD_COMP1_LEAD not in passing_batch_constructs[c1_bid]
or (sec_b_err is None and c1_bid not in tmp_c1_sec)
):
mix_ok = False
sec_input_missing_or_malformed = True
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {mlbl}.comp1_expression_batch_id={c1_bid!r} "
f"must reference a declared passing {_SHIELD_COMP1_LEAD} batch covered by sec_mals_dls.expression_batch_ids",
)
c2_bid = m_rec.get("comp2_expression_batch_id")
if (
type(c2_bid) is not str
or not c2_bid
or c2_bid != c2_bid.strip()
or c2_bid not in passing_batch_constructs
or _SHIELD_COMP2_LEAD not in passing_batch_constructs[c2_bid]
or (sec_b_err is None and c2_bid not in tmp_c2_sec)
):
mix_ok = False
sec_input_missing_or_malformed = True
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {mlbl}.comp2_expression_batch_id={c2_bid!r} "
f"must reference a declared passing {_SHIELD_COMP2_LEAD} batch covered by sec_mals_dls.expression_batch_ids",
)
m_mon, m_mon_err = _shield_check_num(m_rec.get("monomer_pct"), f"{mlbl}.monomer_pct", lo=0.0, hi=100.0)
if m_mon_err is not None:
mix_ok = False
sec_input_missing_or_malformed = True
_escalate("HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {m_mon_err}")
elif m_mon is not None:
valid_mix_monomers.append(m_mon)
m_pdi, m_pdi_err = _shield_check_num(m_rec.get("dls_pdi"), f"{mlbl}.dls_pdi", lo=0.0, hi=1.0)
if m_pdi_err is not None:
mix_ok = False
sec_input_missing_or_malformed = True
_escalate("HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {m_pdi_err}")
elif m_pdi is not None:
valid_mix_pdis.append(m_pdi)
m_no_agg = m_rec.get("no_aggregates_or_precipitation")
if type(m_no_agg) is not bool:
mix_ok = False
sec_input_missing_or_malformed = True
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {mlbl}.no_aggregates_or_precipitation must be strict bool",
)
m_qc = m_rec.get("qc_passed")
if type(m_qc) is not bool:
mix_ok = False
sec_input_missing_or_malformed = True
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {mlbl}.qc_passed must be strict bool",
)
m_mon_oos = bool(m_mon is not None and m_mon < _SHIELD_MIN_MONOMER_PCT)
m_pdi_oos = bool(m_pdi is not None and m_pdi > _SHIELD_MAX_DLS_PDI)
m_agg_oos = bool(m_no_agg is False)
if m_mon_oos or m_pdi_oos or m_agg_oos:
mix_ok = False
quant_sec_failed = True
if m_qc is False:
sec_valid_out_of_spec = True
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"PHYSICOCHEMICAL_OUT_OF_SPEC_MATERIAL_UNQUALIFIED_HOLD: {mlbl} (mixture_id={mid_s!r}) "
f"failed per-mixture co-formulation QC (monomer_pct={m_mon}, dls_pdi={m_pdi}, "
f"no_aggregates={m_no_agg}) with consistent qc_passed=False",
)
else:
sec_input_missing_or_malformed = True
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {mlbl} (mixture_id={mid_s!r}) "
f"per-mixture SEC-MALS/DLS threshold failure contradicts qc_passed={m_qc!r}",
)
elif m_qc is False:
mix_ok = False
sec_input_missing_or_malformed = True
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {mlbl}.qc_passed=False without out-of-spec measurement",
)
m_eq_attested: bool | None = None
if "equimolar_1to1_molar_ratio_attested" in m_rec:
raw_eq = m_rec.get("equimolar_1to1_molar_ratio_attested")
if raw_eq is not True:
mix_ok = False
sec_input_missing_or_malformed = True
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {mlbl}.equimolar_1to1_molar_ratio_attested "
f"must be literal boolean True when supplied (got {raw_eq!r})",
)
else:
m_eq_attested = True
m_ratio_basis: str | None = None
if "ratio_basis_attestation" in m_rec:
raw_rb = m_rec.get("ratio_basis_attestation")
if type(raw_rb) is not str or raw_rb not in _allowed_mix_ratio_basis_tokens:
mix_ok = False
sec_input_missing_or_malformed = True
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {mlbl}.ratio_basis_attestation "
f"must be in {sorted(_allowed_mix_ratio_basis_tokens)} when supplied (got {raw_rb!r})",
)
else:
m_ratio_basis = raw_rb
if mix_ok and mid_s is not None and type(c1_bid) is str and type(c2_bid) is str:
candidate_passing_mixtures[mid_s] = (c1_bid, c2_bid)
candidate_mixture_ratio_meta[mid_s] = {
"equimolar_1to1_molar_ratio_attested": m_eq_attested,
"ratio_basis_attestation": m_ratio_basis,
}
if valid_mix_monomers and ck_mon is not None and ck_mon > min(valid_mix_monomers) + 1e-9:
top_sec_overstated = True
sec_input_missing_or_malformed = True
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: top-level cocktail_1to1_monomer_pct={ck_mon:.2f}% "
f"overstates worst per-mixture monomer_pct={min(valid_mix_monomers):.2f}%",
)
if valid_mix_pdis and dls_pdi is not None and dls_pdi < max(valid_mix_pdis) - 1e-9:
top_sec_overstated = True
sec_input_missing_or_malformed = True
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: top-level dls_pdi={dls_pdi:.4f} "
f"understates worst per-mixture dls_pdi={max(valid_mix_pdis):.4f}",
)
if sec_valid_out_of_spec and sec_input_missing_or_malformed:
sec_qc_cls = "BOTH_OUT_OF_SPEC_AND_MALFORMED_INPUT_HOLD"
elif sec_valid_out_of_spec: